---
title: "struts2 国际化"
author: "onlyor"
date: "2012-11-08T14:49:22Z"
tags: []
categories: ["编程语言"]
slug: "struts2"
draft: false
lastmod: "2012-11-08T15:19:01Z"
id: 1720340
url: "https://onlyor.iteye.com/blog/1720340"
---

http://www.cnblogs.com/langlang/archive/2010/01/14/1647627.html  

在struts2中需要做国际化的有：
jsp页面的国际化，action错误信息的国际化，转换错误信息的国际化，校验错误信息的国际化
在之前的例子中已经做过和国际化相关的例子了，在struts.xml中配置过
 
1.	<constant name="struts.custom.i18n.resources" value="message"></constant>   
 
其中的message就是国际化资源文件的baseNmae。
我们先看看简单的在jsp中进行国际化
在src目录下新建message_en_US.properties，内容为
hello=add user
新建message_zh_CN.properties文件，内容为
hello=\u589e\u52a0\u7528\u6237
然后修改register2.jsp
要想使用国际化显示，可以将信息添加到<s:text></s:text> 标签中，也可以放在<s:i18n></s:i18n> 中，
在这里，先使用标签 <s:text></s:text>
增加以下内容：
 <s:text name="hello"></s:text>   
重启服务器后，浏览该页，默认会显示出“增加用户”，可以在IE中打开Internet选项，在常规中选择语言，增加英语（美国）,然后设置为第一项，刷新就可以看到输出“add user”。