刘政道 - 应用程序框架

《31天学会CRM项目开发(C#编程入门及项目实战)》作者,IT经理,程序员
  博客园  :: 新随笔  :: 联系 :: 管理

转贴: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}