Struts2.0国际化
来源:互联网 发布:java模板引擎 编辑:程序博客网 时间:2024/05/22 12:21
struts2的国际化分三种情况:前台页面的国际化,Action类中的国际化,配置文件的国际化。
首先指定全局的国际化资源文件:
在配置文件struts.xml中引入
<constant name="struts.custom.i18n.resources" value="message"></constant>(注意位置)
或
在struts.properties文件中指定如下一行:
struts.custom.i18n.resources=message
指定的国家化资源文件即为
xxx_语言_国家.properties
message_zh_CN.properties(简体中文资源文件)
message_en_US.properties(美国英语资源文件)
(1).JSP页面上的国际化(使用struts2的<s:text .../>):
<s:i18n name="message"><!--国际化资源文件前缀名-->
</s:i18n>
message_en_US.properties文件配置:
hello=hello world,{0}
message_zh_CN.properties文件配置:
hello=你好,{0}
(2)表单元素的Label国际化:
未国际化:
<s:textfield name="username" label="username"></s:textfield>
<s:textfield name="password" label="password"></s:textfield>
国际化后:
<s:textfield name="username" key="uname"></s:textfield>
<s:textfield name="password" key="pword"></s:textfield>
message_en_US.properties文件,配置:
uname=username
pword=password
message_zh_CN.properties文件,配置:
uname=用户名
pword=密码
(3).Action中的国际化:
未国际化:
this.addFieldError("username", "the username error!");
this.addFieldError("password", "the password error!");
国际化后:
this.addFieldError("username", "username.error");
this.addFieldError("password", "password.error");
message_en_US.properties文件配置:
username.error = the username error !
password.error = the password error!
message_zh_CN.properties文件配置:
username.error=用户名错误!
username.error=密码错误!
(4).配置文件中的国际化:
以输入校验的LoginAction-validation.xml为例:
未国际化:
<field name="username">
国际化后:
<field name="username">
message_en_US.properties文件配置:
username.empty = the username
username.size = the size of username shoule be between 6 and 12 !
password.empty = the password should not be empty !
password.size = the size of password shoule be between 6 and 12 !
message_zh_CN.properties文件配置:
username.empty =用户名不能为空 !
username.size = 用户名长度在6到12 !
password.empty =密码不能为空 !
password.size = 密码长度在6到12 !
注:message_zh_CN.properties这个国际化资源文件不允许包含非西欧字符。
Java提供了一个工具来处理该文件中的中文:native2ascii,这个工具可以在%JAVA_HOME%/bin路劲下找到。
- struts2.0 国际化
- struts2.0国际化
- Struts2.0国际化支持
- Struts2.0国际化
- Struts2.0国际化
- struts2.0之国际化
- Struts2.0国际化支持
- Struts2.0国际化
- 三、struts2.0国际化
- Struts2国际化
- struts2 国际化
- struts2国际化
- Struts2国际化
- Struts2国际化
- struts2 国际化
- struts2 国际化
- struts2国际化
- struts2国际化
- Win8.1 下 VS2010、VS2012中 扩展管理器 visual Assist X 启用,中文乱码 解决方案
- 堆排序
- sicily 1136(线段树+最大子数组)
- Qt基本特性
- KNN算法详解
- Struts2.0国际化
- Cocos2d-JS屏幕适配(NO-BORDER模式)
- 保持边缘的滤波函数————Guided Image Filtering
- 7、缓存、不可变类
- 第3周项目找对象--三角形类
- iOS开发中 常用的SQLite函数
- 新技术再次提升了Chrome的JavaScript载入效率
- 【数位DP】POJ 3252 Round Numbers
- JavaWeb中的绝对路径和相对路径问题