JSF中使用资源文件 或Richfaces使用资源文件 或Javabean使用资源文件

转贴:http://www.ceapet.com/topic19.html

创建资源文件p.properties,内容如下
name=admin
age=28
org=ceapet.com
email=admin@ceapet.com

将资源文件放在一个位置,例如放在webapps/ROOT/modules/下

编辑main.java或你要使用的javabean
import java.io.*;
import java.util.Properties;
public Properties p;
public Properties getP()
{
if(p == null)
{
try
{
String filename = "..\\webapps\\ROOT\\modules\\p.properties";//windows 路径
File f = new File(filename);
if(f.exists())
{
InputStream is = new FileInputStream(filename);
p = new Properties();
p.load(is);
is.close();
}
else
System.out.print("warning:the file " + filename + " not found!");
}catch(Exception ex){ex.printStackTrace();}
}
return p;
}
在xhtml页面中调用时,输入#{main.p.name}或#{main.p.org} 

原文地址:https://www.cnblogs.com/liuzhengdao/p/1630220.html