struts 的国际化中的  properties  里面的value 可不可以动态啊就比如用代码修改 里面的数据用什么方法比较好?用代码修改property文件?还是用代码动态生成Key 和value 存起来

解决方案 »

  1.   

    http://wellfrog.iteye.com/blog/611934
    http://blog.csdn.net/liuyuhua0066/article/details/7635375
      

  2.   

    http://blog.csdn.net/liuyuhua0066/article/details/7635375
      

  3.   


    public class GetProperty {
      public static String readValue(String filePath,String key){
      Properties props = new Properties();
      try {
      InputStream ips = new BufferedInputStream(new FileInputStream(filePath));
      props.load(ips);
      String value = props.getProperty(key);
      System.out.println(key+"="+value);
      return value;
      } catch (FileNotFoundException e) {
      e.printStackTrace();
      return null;
      } catch (IOException e) {
      e.printStackTrace();
      return null;
      }
      }
      //读取全部信息
      public static void readProperties(String filePath) {
      Properties props = new Properties();
      try {
      InputStream ips = new BufferedInputStream(new FileInputStream(filePath));
      props.load(ips);
      Enumeration enum = props.propertyNames();
      while(enum.hasMoreElements()){
      String key = (String)enum.nextElement();
      String value = props.getProperty(key);
      System.out.println(key+"="+value);
      }
      } catch (FileNotFoundException e) {
      e.printStackTrace();
      } catch (IOException e) {
      e.printStackTrace();
      }
      }
      public static void writeProperties(String filePath,String paraKey,String paraValue){
      Properties props = new Properties();
      try {
      OutputStream ops = new FileOutputStream(filePath);
      props.setProperty(paraKey, paraValue);
      props.store(ops, "set");
      } catch (IOException e) {
      e.printStackTrace();
      }
      }
    }
      

  4.   

    觉得一般不太需要动态修改资源文件的内容,通常情况下它是配置好的,这样每次读取也都是相同的值。
    动态修改的话,这样在用做按钮或菜单的国际化时,导致这次看是某值,下次看又是另一个值了,有点乱。要改的话,也可以
    Properties prop = new Properties(); 
           try { 
               InputStream is= new FileInputStream(...); 
               prop.load(is); 
               OutputStream os= new FileOutputStream(...); 
               prop.setProperty(propertyName, propertyValue); 
               prop.store(os, "comments"); 
               os.close();
               is.close(); 
           } catch (IOException e) {        } 但有注意,修改之后,是否能立刻生效
      

  5.   

    对啊,修改后可不可以立即生效啊,这也是个问题 ,
    不过我找到了这样一项配置 
    struts.i18n.reload=false
    指定是否在每次请求时自动重新加载资源包。但是还没有用过,不知道信不信。
      

  6.   

    <s:property value="#request.genre.<s:text name='genre.genreName'/>" />struts的标签的 ognl表达式可不可以像这样评啊
    为什么这个不行,不报错,没有输出
      

  7.   

    又遇到一问题,
    就是用了struts后都是把数据存在 session,request这些范围内,然后转发到某个jsp
    现在我的问题是这个jsp里面有个循环
    循环的这个对象又要去查询一下数据(比如用ID去查询数据)也就是在
    <s:iterator value="#gen1.products" var="pbase1"></s:iterator>
    这个迭代器里面访问 action中的方法 查询数据。这个该怎么实现
    用OGNL的静态方法 action里面的一些 业务bean 会为null现在就是 想调用action中的方法 ,并且可以用struts的一些特效,
    比如业务bean  不用自己创建
    大神们有什么好的想法啊,在线等啊,冰天雪地跪等解决方案