当页面请求时,把本地信息(主要为Accept-Language: en-US,zh-cn;q=0.5)传递给tomcat,struts从tomcat中获取本地信息,struts把每一个要请求的用户的local放到session中,根据session的信息来调用国际化资源文件。
我们可以手动来构造local信息并把它放到struts的session中,这样就可以手动切换页面编码方式。
如:在某个action中
String language = request.getParameter("lang");//从前一页接收的变量,其值为"zh"或"en"
Locale currentLocale = Locale.getDefault();
if ("zh".equals(language )) {
currentLocale = new Locale("zh","CN");
}else if ("en".equals(language )) {
currentLocale = new Locale("en","US");
}
this.setLocale(request, currentLocale);
return mapping.findForward("index");//最后转到某某页,如index.jsp页