Struts 国际化 i18N properties 数据动态 struts 的国际化中的 properties 里面的value 可不可以动态啊就比如用代码修改 里面的数据用什么方法比较好?用代码修改property文件?还是用代码动态生成Key 和value 存起来 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://wellfrog.iteye.com/blog/611934http://blog.csdn.net/liuyuhua0066/article/details/7635375 http://blog.csdn.net/liuyuhua0066/article/details/7635375 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(); } }} 觉得一般不太需要动态修改资源文件的内容,通常情况下它是配置好的,这样每次读取也都是相同的值。动态修改的话,这样在用做按钮或菜单的国际化时,导致这次看是某值,下次看又是另一个值了,有点乱。要改的话,也可以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) { } 但有注意,修改之后,是否能立刻生效 对啊,修改后可不可以立即生效啊,这也是个问题 ,不过我找到了这样一项配置 struts.i18n.reload=false指定是否在每次请求时自动重新加载资源包。但是还没有用过,不知道信不信。 <s:property value="#request.genre.<s:text name='genre.genreName'/>" />struts的标签的 ognl表达式可不可以像这样评啊为什么这个不行,不报错,没有输出 又遇到一问题,就是用了struts后都是把数据存在 session,request这些范围内,然后转发到某个jsp现在我的问题是这个jsp里面有个循环循环的这个对象又要去查询一下数据(比如用ID去查询数据)也就是在<s:iterator value="#gen1.products" var="pbase1"></s:iterator>这个迭代器里面访问 action中的方法 查询数据。这个该怎么实现用OGNL的静态方法 action里面的一些 业务bean 会为null现在就是 想调用action中的方法 ,并且可以用struts的一些特效,比如业务bean 不用自己创建大神们有什么好的想法啊,在线等啊,冰天雪地跪等解决方案 【300分】Ehcache,flush到磁盘后,怎么再读到这些object呢? 关于导航栏的问题 java 调用存储过程 163博客日历原理 JSP中的树型问题.请大家指导一下! 怎么实现图片的定时翻动? page指令的contentType属性 js如何实现点击一个连接后打开用户指定的客户端exe程序 哪位高手帮帮忙啊,跪谢了 jsp+sqlserver+tomcat5 求救 一个中文乱码问题我第一次遇到,郁闷,求大仙。。。 新手请指教 谢谢了!!!
http://blog.csdn.net/liuyuhua0066/article/details/7635375
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();
}
}
}
动态修改的话,这样在用做按钮或菜单的国际化时,导致这次看是某值,下次看又是另一个值了,有点乱。要改的话,也可以
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) { } 但有注意,修改之后,是否能立刻生效
不过我找到了这样一项配置
struts.i18n.reload=false
指定是否在每次请求时自动重新加载资源包。但是还没有用过,不知道信不信。
为什么这个不行,不报错,没有输出
就是用了struts后都是把数据存在 session,request这些范围内,然后转发到某个jsp
现在我的问题是这个jsp里面有个循环
循环的这个对象又要去查询一下数据(比如用ID去查询数据)也就是在
<s:iterator value="#gen1.products" var="pbase1"></s:iterator>
这个迭代器里面访问 action中的方法 查询数据。这个该怎么实现
用OGNL的静态方法 action里面的一些 业务bean 会为null现在就是 想调用action中的方法 ,并且可以用struts的一些特效,
比如业务bean 不用自己创建
大神们有什么好的想法啊,在线等啊,冰天雪地跪等解决方案