struts实现语言自动切换
2017-03-17 20:37
344 查看
需求
1、通过点击需要转换的语言,来达到显示的数据为相应的语言。
demo
Action
/**
* Created by zhou on 2017/3/17.
*/
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 locale = Locale.getDefault();
if("zh".equals(lang)){
locale = new Locale("zh","CN");
}else if ("en".equals(lang)){
locale = new Locale("en","US");
}
this.setLocale(request,locale);
return mapping.findForward("index");
}
}
jsp
<%--
Created by IntelliJ IDEA.
User: zhou
Date: 2017/3/10
Time: 20:39
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
<a href ="login.jsp">登录</a>
<a href="changeLang.do?lang=zh">中文</a> <a href="changeLang.do?lang=en">英文</a>
</body>
</html>
sturts-config.xml
<action path="/changeLang"
type="com.zhou.struts.ChangeLanguageAction"
>
<forward name="index" path="/index.jsp"/>
</action>
效果图
感谢您的宝贵时间···
1、通过点击需要转换的语言,来达到显示的数据为相应的语言。
demo
Action
/**
* Created by zhou on 2017/3/17.
*/
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 locale = Locale.getDefault();
if("zh".equals(lang)){
locale = new Locale("zh","CN");
}else if ("en".equals(lang)){
locale = new Locale("en","US");
}
this.setLocale(request,locale);
return mapping.findForward("index");
}
}
jsp
<%--
Created by IntelliJ IDEA.
User: zhou
Date: 2017/3/10
Time: 20:39
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
<a href ="login.jsp">登录</a>
<a href="changeLang.do?lang=zh">中文</a> <a href="changeLang.do?lang=en">英文</a>
</body>
</html>
<%-- Created by IntelliJ IDEA. User: zhou Date: 2017/3/11 Time: 8:32 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> <html> <head> <title>Title</title> </head> <body> <form action="login.do" method="post"> <bean:message key="login.form.field.username"/>: <input type="text" name="username"><br> <bean:message key="login.form.field.password"/>: <input type="password" name="password"><br> <input type="submit" value="<bean:message key="login.form.button.login"/>"> </form> </body> </html>
sturts-config.xml
<action path="/changeLang"
type="com.zhou.struts.ChangeLanguageAction"
>
<forward name="index" path="/index.jsp"/>
</action>
效果图
感谢您的宝贵时间···
相关文章推荐
- android实现多语言自动切换字体
- 使用jquery-i18n-properties实现多语言切换,自动选择,及持久化
- Struts实现多国语言切换
- PHP - 实现多语言自动切换
- Struts实现多国语言切换
- VS+QT实现语言自动切换
- PHP - 实现多语言自动切换
- Struts实现多国语言切换
- Struts实现多国语言切换
- 利用INI文件实现界面无闪烁多语言切换(Delphi)
- Struts实现自动多文件上传
- php实现首页自动选择语言转跳
- php实现首页自动选择语言转跳
- 网站首页的自动语言切换
- PHP实现首页自动选择语言转跳
- 重写struts标签,实现错误输入项目背景色自动变化。
- dephi 程序输入法中英文自动切换实现的源代码
- 利用RSVIEW32的事件机制实现软冗余自动切换
- dephi 程序输入法中英文自动切换实现的源代码
- 自动实现php4和php5环境的切换......