【发布时间】:2014-02-13 22:09:54
【问题描述】:
我想从我的 jsf 2.2 项目中的属性文件中读出。我使用 Eclipse 开普勒。
我尝试在包含 de.exanple 包的文件夹 src 中的 java-bean 中使用它。 bean 的文件名为 PageServiceBean.java。
属性文件位于WEB-INF/resources/prop 文件夹中。属性文件称为 config.properties。
我已经读到我可以使用javax.faces.WEBAPP_RESOUCRES_DIRECTORY 参数名称和/WEB_INF/resoucres 之类的参数值更改web.xml 文件中jsf 2.2 中的资源文件夹
但我没有得到配置文件的路径。 你能告诉我在哪里可以得到路径名。我想我必须使用相对路径名。 你能帮帮我吗?
更新
我执行你喜欢的第二个代码片段:
private Properties getProperties() {
Properties prop = new Properties();
try {
//load a properties file
prop.load(new FileInputStream("config2.properties"));
} catch(Exception e) {
}
return prop;
}
public void setProperty1(Integer value) {
Properties prop = getProperties();
prop.setProperty("ort", value.toString());
try {
prop.store(new FileOutputStream("config2.properties"), null);
Properties prop2 = getProperties();
} catch (IOException ex) {
Logger.getLogger(PageServiceBean.class.getName()).log(Level.SEVERE, null, ex);
}
}
有效!我使用Properties prop3 = getProperties(); 来读取属性文件config2.properties。该文件存储在 Eclipse 主路径 ECLIPSE_HOME = C:\elipse_jee\eclipse 中。我可以将路径更改为特定路径,例如WEB_INF/resources吗?
【问题讨论】:
标签: jsf jsf-2 path properties-file webcontent