Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )
Struts switching of international English
This is the initial page, now need to implement the functionality is to click on Simplified Chinese or English text for page in English switch
The first step in
the configuration in reresources good in two files: d_zh_CN.properties; d_en_US.properties
- d_zh_CN.properties written inside
Note: \ u7528 such code is encrypted Chinese
uname=\u7528\u6237\u540D
upwd=\u5BC6\u7801
login=\u767B\u5F55
- d_en_US.properties written inside
uname=UserName
upwd=UserPwd
login=Login
The second step
strust.xml file configured to allow the frame to find the configuration file for the language
<constant name="struts.custom.i18n.resources" value="d"></constant>
The third step
is displayed in the file configuration jsp
<form action="">
<s:text name="uname"></s:text> <input type="text" name=""/><br/>
<s:text name="upwd"></s:text><input type="password" name="" ><br/>
<input type="submit" value='<s:text name='login'></s:text>'/>
</form>
<a href="跳转页面的服务方法?request_locale=zh_CN">简体中文</a>
<a href="a跳转页面的服务方法??request_locale=en_US">English</a>
The fourth step
results shown in FIG.
Knowledge summary
1.zh_CN与en_US的地区语言简写,而Struts是一只规范框架,所以命名时只能是前缀_zh_CN
2.在Struts.xml中必须允许框架查找语言的配置文件;要不然将不能切换
3.在jsp中需要中英文切换的文字都需要用<s:text name=“properties配置文件中的键”>显示