struts.xml文件:
<struts>
<include file="struts-default.xml" />
<constant name="struts.custom.i18n.resources" value="mess"></constant> //value值为数据转换文件mess开头 的
<package name="com.action" extends="struts-default">
<action name="input" class="com.action.ChangeLocale" >
// <result type="redirect">
${href}</result>//返回原来的路径 实际使用中不能使用重定向
<result >/index.jsp</result>
<interceptor-ref name="i18n" />
</action>
</package>
</struts>
mess.properties 默认数据转换 比如 hello=你好
mess_en.properties 另外的数据转换 hello=hello //英文
<body>
<a href="input?request_locale=zh_CN&href=<%=basePath%>">中文 </a><br/> //超链接同时传递路径参数
<a href="input?request_locale=en_US&href=<%=basePath%>">英文</a>
<s:text name="hello"></s:text>
</body> 超链接传递参数切换
ChangeLocale.java
public class ChangeLocale extends ActionSupport {
private String href;
public String getHref() {
return href;
}
public void setHref(String href) {
this.href = href;
}
public String execute(){
HttpServletRequest request = ServletActionContext.getRequest();
this.setHref(request.getParameter("href")); //获取传递过来的参数
return SUCCESS;
}
}