Struts2 中国际化配置文件中需注意的问题

来源:互联网 发布:potplayer播放器mac版 编辑:程序博客网 时间:2024/05/22 17:18

Struts2的错误信息可分为:field级别的错误和action级别的错误

 

在国际化的配置文件中:分为
1,全局化的国际化资源文件,如: message_en_US.properties和message_zh_CN.properties
2,包级别的国际化资源文件:如:package_en_US.properties和package_zh_CN.properties
3,类级别的国际化资源文件:如:RegisterAction_en_US.properties和RegisterAction_zh_CN.properties

 注意:全局化的国际化资源文件放在src目录下,并且要在struts.xml文件中配置如下:
 <constant name="struts.custom.i18n.resources" value="message"></constant>
 而包级别和累级别的文件放在对应的类下,
 也包括RegisterAction-validation.xml验证文件也和类在同意目录下
 
 
4,在标签:<s:i18n name="temp">
   <s:text name="hello">
    <s:param>zhangsan</s:param>
   </s:text>
  </s:i18n>
    所使用的国际化资源文件是:file_en_US.properties和file_zh_CN.properties放在src文件夹下
    在此所使用的文件中,Ii18n只找上两文件,<s:i18n name="temp">name属性对应文件的名字file,
    后面<s:text name="hello">name属性对应文件中的key值,然后输出value值,并在页面上显示。
 
5,要直接在页面上显示国际化信息使用标签<s:text name="add.user"></s:text>
  name属性对应国际化资源文件中的key值

6, <s:fielderror cssStyle="color:red"/>只能显示field级别的错误信息
   <s:actionerror cssStyle="color:red"/>只能显示action级别的错误信息
   在表单验证的配置文件中只能显示filed级别的错误信息
   this.addActionError(this.getText("username.invalid",str));显示的是action级别的错误信息
  

原创粉丝点击