Struts2国际化
2014-07-17 14:08
169 查看
使用Struts2的国际化机制能够将不同语言版本的字符保存在属性文件中,在不需要重新开发应用的前提下,实现不同语言版本的应用。
1、视图中的文本
2、视图中标签的属性
如果采用JSP文件,如register.jsp
Action类如果需要使用国际化的文本,往往继承ActionSupport类,调用ActionSupport类中的getText方法即可获得国际化资源。
4、使用校验框架的配置信息
创建messageResource.properties文件
使用多个国际化资源文件
为了支持多个语言版本的国际化资源文件,定义资源文件的命名规则:
使用native2ASCII messageResource_zh_CN.proterties temp.properties
将生成文件temp.properties中的内容拷贝至messageResource_zh_CN.proterties
支持美国英语的资源文件:messageResource_en_US.properties
配置文件struts.properties
1、视图中的文本
2、视图中标签的属性
如果采用JSP文件,如register.jsp
<body> <s:text name="register.info"></s:text><br> <s:form action="Customer"> <s:textfield name="custname" label="Input your custname"></s:textfield> <s:password name="pwd" label="Input your password"></s:password> <s:textfield name="age" label="Input your age"></s:textfield> <s:textfield name="address" label="Input your address"></s:textfield> <s:submit value="Register"></s:submit> </s:form> </body>3、Action类中的文本
Action类如果需要使用国际化的文本,往往继承ActionSupport类,调用ActionSupport类中的getText方法即可获得国际化资源。
4、使用校验框架的配置信息
创建messageResource.properties文件
#The Text register.info=Please input your register Info: #The Form custname.label=Input your name pwd.label=Input your password age.label=Input your age address.label=Input your address register.button=Register New Customer创建struts.properties文件(在src目录创建,是一个属性文件,文件中都是以key=value姓氏定义的键值对),配置资源文件的名字
struts.custom.i18n.resources=messageResource修改register.jsp文件
<body> <s:text name="register.info"></s:text><br> <s:form action="Customer!register"> <s:textfield name="custname" key="custname.label"></s:textfield> <s:password name="pwd" key="pwd.label"></s:password> <s:textfield name="age" key="age.label"></s:textfield> <s:textfield name="address" key="address.label"></s:textfield> <s:submit name="tijiao" key="register.button"></s:submit> </s:form> </body>
使用多个国际化资源文件
为了支持多个语言版本的国际化资源文件,定义资源文件的命名规则:
资源文件基础名_语言版本缩写_国家代码缩写.properties例支持中文的资源文件:messageResource_zh_CN.properties
#The Text register.info=请输入您的注册信息: #The Form custname.label=输入用户名: pwd.label=输入密码: age.label=输入年龄: address.label=输入地址 register.button=注册新用户
使用native2ASCII messageResource_zh_CN.proterties temp.properties
将生成文件temp.properties中的内容拷贝至messageResource_zh_CN.proterties
#The Text register.info=\u8bf7\u8f93\u5165\u60a8\u7684\u6ce8\u518c\u4fe1\u606f\uff1a #The Form custname.label=\u8f93\u5165\u7528\u6237\u540d\uff1a pwd.label=\u8f93\u5165\u5bc6\u7801\uff1a age.label=\u8f93\u5165\u5e74\u9f84\uff1a address.label=\u8f93\u5165\u5730\u5740 register.button=\u6ce8\u518c\u65b0\u7528\u6237
支持美国英语的资源文件:messageResource_en_US.properties
#The Text register.info=Please input your register Info: #The Form custname.label=Input your name pwd.label=Input your password age.label=Input your age address.label=Input your address register.button=Register New Customer
配置文件struts.properties
struts.custom.i18n.resources=messageResource_zh_CN #struts.custom.i18n.resources=messageResource_en_US
相关文章推荐
- Struts2 输入校验(Action中使用国际化资源文件、校验器校验)
- struts2 国际化
- struts2 国际化
- struts2--struts2国际化(使用占位符)
- 码农小汪-struts2学习6-国际化
- 菜鸟学SSH(二)——Struts2国际化手动切换版
- Struts2 的国际化实现
- struts2表单验证初步及国际化实现(学习总结)
- 【Struts2】(3)Struts2国际化、Struts2上传下载、Struts2标签使用
- struts2系列学习笔记(13)---------------Struts2国际化
- struts2实现国际化
- struts2国际化语言切换
- 笔记:Struts2 国际化
- struts2中的国际化
- Struts2教程10:国际化
- SSH(二)~——Struts2国际化手动切换版
- Struts2教程10:国际化
- Struts2通过过滤器对每个jsp页面国际化
- Struts2 中国际化配置文件中需注意的问题
- Struts2与国际化