通过页面设置国际化语言

Struts2.X 中通过页面设置国际化语言:http://wing123.iteye.com/admin/blogs/384118

 

关键是要知道struts在哪里设置国际化语言的,用什么方式设置

 

jsp代码:

 

-------------------------------------------------------------

<body>
<a href="login.jsp">Login</a>
<p>
<a href="changelang.do?lang=zh">中文</a>
<a href="changelang.do?lang=en">英文</a>

<p>
<a href="login_jstl.jsp">Login_JSTL</a>
</body>

-------------------------------------------------------------

 

struts-config.xml

    <action path="/changelang"
            type="com.bjsxt.struts.ChangeLanguageAction">
        <forward name="success" path="/index.jsp"></forward>
    </action>

 

 

 

ChangeLanguageAction.java

 

/**
* 手动改变Locale
* @author Administrator
*
*/
public class ChangeLanguageAction extends Action {

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String lang = request.getParameter("lang");
Locale currectLocale = null;
if("zh".equals(lang)) {
currectLocale = new Locale("zh", "CN");
}else if("en".equals(lang)){
currectLocale = new Locale("en", "US");
}
request.getSession().setAttribute (Globals.LOCALE_KEY , currectLocale);
//this.setLocale(request, currectLocale);
return mapping.findForward("success");
}

}

 

 

你可能感兴趣的:(jsp,xml,struts)