Struts2_13_Struts国际化

国际化((Internationlization):通俗地讲,就是让软件实现对多种语言的支持;


 不带参数


 需要在struts.xml中添加配置:

constant name="struts.custom.i18n.resources" value="international"></constant>

 value值代表着properties文件的名字

在src目录下新建international.properties

userName=\u7528\u6237\u540d
password=\u5bc6\u7801
login=\u767b\u5f55

properties文件不支持中文,要把中文转换成相对于的Unicode编码。

推荐转换网址:http://tool.chinaz.com/tools/unicode.aspx

实现多元化,就新建其他properties文件,中文;international_zh_CN.properties

userName=\u7528\u6237\u540d
password=\u5bc6\u7801
login=\u767b\u5f55

英文:international_en_US.properties

userName=userName
password=password
login=login

新建login.jsp测试:<s:textname=""></s:text> 访问国际化资源

<body>
<table>
	<tr>
		<td><s:text name="userName"></s:text></td>
		<td><input type="text"/></td>
	</tr>
	<tr>
		<td><s:text name="password"></s:text></td>
		<td><input type="button" value="<s:text name='login'></s:text>"/></td>
	</tr>
</table>
</body>

当浏览器为中文时:

当浏览器为英文时:


带参数:

模拟欢迎界面:

需要在properties文件添加:

welcomeInfo=\u6b22\u8fce\u4f60\uff0c{0}
welcomeInfo=welcome,{0}

welcome页面:

<s:text name="welcomeInfo">
	<s:param>Jack</s:param>
</s:text>

当浏览器为中文:

当浏览器为英文:

猜你喜欢

转载自blog.csdn.net/qq_27163329/article/details/81608294