利用struts默认将 Locale 放到 session 中的特性,完成采用编程的方式切换语言设置
前台:
<a href="login.do?lang=zh">中文</a>
<a href="login.do?lang=en">英文</a>
后台:
String lang = request.getParameter("lang");
Locale currentLocale = Locale.getDefault();
if("zh".equals(lang)){
currentLocale = new Locale("zh","CN"); //第一个参数为“语言”,第二个参数为国家 根据这连个参数取相应的资源文件
}else if("en".equals(lang)){
currentLocale = new Locale("en","US");
}
// reqquest.getSession().setAttribute(Globals.LOCALE_KEY , currentLocale);
this.setLocale(request , currentLocale); //与上面一句作用一样
本文介绍如何使用Struts框架实现网站的语言切换功能。通过在前端提供链接选择不同的语言,并在后端通过设置Locale来改变显示的语言,使得应用程序能够支持多种语言环境。
1721

被折叠的 条评论
为什么被折叠?



