一、在strute.xml中指定资源文件的基名。
在strute.xml文件的struts标签里加入如下代码:
<constant name="struts.custom.i18n.resources" value="message"/>
在src目录下添加分别为 中文-中国 和 英文-美国 的资源文件。那么对应的文件名就是:
中文-中国:message_zh_CN.properties
英文-美国:message_en_US.properties
message_zh_CN.properties代码:
title=注册 form.email=邮箱: form.password=密码: form.repassword=重复密码: form.phone=电话: form.submit=提交
message_en_US.properties代码:
title=register form.email=eMail: form.password=password: form.repassword=repassword: form.phone=phone: form.submit=submit
然后开始写我们的action,只需要写一个execute方法来接收就行
public class LanguageAction {
public String execute(){
return "success";
}
}
三、实现JSP页面信息的国际化显示
<a href="language_action?request_locale=zh_CN">中文</a>||<a href="language_action?request_locale=en_US">英文</a>
把和显示相关的文字都替换成 <s:text name="对应资源文件的键"/> 其中属性 name 的值为资源文件里相对应的key。如:<s:text name="title"/> <s:text name="form.email"/>