struts2实现国际化

来源:互联网 发布:伊势神宫 知乎 编辑:程序博客网 时间:2024/06/05 17:18

第一步:定义属性文件,basename_语言代码_国家代码.properties(如:messageResouce_en_US.properties,messageResouce_zh_CN.properties),

第二步:中文用dos命令:native2ascii messageResouce.properties messageResouce_zh_CN.properties

第三步:设置加载属性文件:在Struts.properties中,定义struts.custom.i18n.resources=路径.messageResource(路径如果和Struts.properties在一起,可省略)

第四步:用struts标签输出,2种方式

1.<s:text name="messageKey"/>:使用s:text标签来输出国际化信息。

输出带参数的,如资源文件中有username={},你好

输出:<s:text name="username">

<s:property>张三</s:property>

 </s:text>

2. <s:property value='%{getText("messageKey")}'/>:使用表达式方式输出国际化信息。(注意:单引号和双引号不能同时出现,或者外单内双,或者外双内单)

第五步:可在控制面板里,更改区域语言选项