struts2的国际化
1.创建资源文件,文件名格式:文件基名_语言代码_国家代码.properties
2.在struts.properties或者sturts.xml中配置常量struts.custom.i18n.resources=文件基名
3.使用:
(1).<s:text name="successPage"></s:text>
(2).<s:property value="%{getText('successPage')}"/>
(3).<s:textfield name="username" key="successPage"></s:textfield>
(4).Action中使用:必须继承ActonSupport类,使用getText(key);如:addFieldError("success",getText("successPage"))
(5).校验文件中使用: <message key="successPage"></message>
注意:表单标签中key属性代替lable属性
语言代码和国家代码可以查看windows控制面板,Internet选项查看
中文文件时,要转码,用jdk自带的native2ascii命令,如:
F:
cd F:/struts/config
native2ascii message.properties message_zh_CN.properties
注意:测试后,没能成功,有待验证。
Action中使用:在Action类路径下,创建ActionName.properties,Action继承Actionsupport类,使用getText(key)方法
package中使用:在package中创建package.properties
jsp中使用:在jsp页面中使用标签
注意:Action中使用只能在指定的Action中使用,跳转到jsp也可以用
package也一样,只能在所在的package中所有的Action中使用
可以在资源文件中使用占位符
login_error_msg={0} is required
在Actio中使用时
this.getText("login_error_msg",new String[]{"usenrame"})
显示的信息就是
username is required
在jsp页面中使用方法
<s:text name="login_error_msg">
<s:param>username</s:param>
</s:text>
username is required
在xml中校验时,要用ognl表达式(老师没讲)

浙公网安备 33010602011771号