abc.properties 并将获取到的值保存入 这个静态变量。 这样你可以再任何一个 jsp 页面直接引用这个java类就可以得到配置文件里面的值,这样设计可以达到一个代码复用的效果。不需要在其他页面重新进行加载文件。
2.这个是java类
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class Constant {
public static String oneLevel = "";
public static String twoLevel = "";
public static String threeLevel = "";
public static String fourLevel = "";
static {
try {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("level.properties");
Properties p = new Properties();
p.load(is);
oneLevel = p.getProperty("common.one");
twoLevel = p.getProperty("common.two");
threeLevel = p.getProperty("common.three");
fourLevel = p.getProperty("common.four");
is.close();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
3.这个是jsp页面
<%@page import="com.newtouch.las.Constants"%>
System.out.println("========="+Constant.oneLevel+"=="+Constant.twoLevel+""+Constant.threeLevel+""+Constant.fourLevel);
4.这个是porpertise文件
<pre name="code" class="html">common.one =10
common.two = 100
common.three = 1000
common.four = 10000