【Struts2复习知识点二十二】- 国际化I18N原理

创建配置文件:格式  文件名_语言_国家.properties (文件名后面都是固定的),如:

app_en_US.properties

app_zh_CN.properties

JAVA调用文件:

View Code
public static void main(String[] args) {
ResourceBundle res = ResourceBundle.getBundle("app", Locale.CHINA);
System.out.println(res.getString("welcome.msg" ));
}


会自动调用   app_zh_CN.properties  文件中的welcome.msg对应的value值。

 

注:properties 不让存中文。解决办法:

1.用JDK中的转换程序 native2ascii.exe 转换成UTF8格式的ascii码。

2.struts1可以装一个插件来解决,struts2也是这么做的。(propertieseditor)

 

posted @ 2012-02-26 12:27  濤叔  阅读(325)  评论(0编辑  收藏  举报