zoukankan      html  css  js  c++  java
  • 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} 

  • 相关阅读:
    2021年2月13
    2021年2月12
    2021年2月11
    2021年2月10
    2021年2月9
    下载优化
    20180301越努力越轻松
    2018-03-01继续完善2
    2018-03-01继续完善
    2018-02-16 GetSameTypeQuestion
  • 原文地址:https://www.cnblogs.com/liuzhengdao/p/1630220.html
Copyright © 2011-2022 走看看