前几天发了一篇Struts国际化的博客——《菜鸟学习SSH(二)——Struts2国际化手动切换版》,有网友提了一个意见,见下图:

于是就有了下面修改的版本:

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> </web-app>

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <constant name="struts.devMode" value="true"></constant>
<constant name="struts.custom.i18n.resources" value="bbs2009"></constant>
<package name="/" namespace="/" extends="struts-default" > <action name="*-*" class="com.lsj.action.{1}Action" method="{2}">
<result>/{1}-{2}.jsp</result>
</action> </package> </struts>

登录页

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>登录</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page"> </head> <body>
<form action="Login-login" method="post">
<s:property value="getText('login.username')"/> <input name="username" />
<s:property value="getText('login.password')"/><input name="password" type="password" />
<input type="submit" value="<s:property value="getText('login.login')"/>" />
</form> </body>
</html>

OK,这样将浏览器的语言设置成中文,那么页面就以中文显示;把浏览器语言设置成英文,页面就以英文显示。这一个版本就是上面那位网友说的那种效果。这个版本实现起来要比上一个要简单,不过之前那种手动修改也有它的作用,大家在上网的时候都见过很多网站上有手动切换显示语言的链接吧(像微软、谷歌的网站上都有)!这是为了让那些身在国外的人能够自己切换到母语的显示页面而做的。这两种方式各有各的作用。

两种方式各司其职,具体要怎么用还得看你想要实现什么样的需求了。这是两种不同的国际化实现方法,今天把这种自动识别浏览器语言的方法也写出来供大家把玩把玩,希望各位玩的开心。

最新文章

  1. scikit-learn 梯度提升树(GBDT)调参小结
  2. iOS网络2——NSURLSession使用详解
  3. bzoj2938: [Poi2000]病毒
  4. 最近新装系统windows8.1+Mac。。。还没装驱动就遇到一堆问题。。。
  5. Echarts个人实例
  6. Android studio 环境搭建
  7. 【Qt】QWidget、QDialog、QMainWindow的异同点【转】
  8. STM32L152 Keil 开发环境 显示Internal command error Flash down
  9. windows笔记-一个简单的windows GUI应用程序
  10. jsp文件上传
  11. 正式学习React(四) 前序篇
  12. HDU 3060 多边形面积并
  13. asp.net 生成xml文件 与 asp生成xml文件
  14. NPOI mvc easyui 根据Excel模板 生成Excel
  15. HTML DOCTYPE文档类型举例说明
  16. Libevent(2.1.8)中的事件结构和管理
  17. 短时间内多个请求状态更新,导致react 不能及时响应问题总结
  18. laravel5.8笔记二:部署
  19. 日常推荐大神操作,如何再oracle中delete数据后恢复
  20. 关于three.js中添加文字的方式[转]

热门文章

  1. Servlet路径跳转问题
  2. 【laravel5.4】安装predis
  3. Easyui入门视频教程 第06集---Layout初始化和属性方法使用
  4. Swift打印Debug日志,实现Release下不打印
  5. public-private-protected-默认缺省 的区别
  6. Mysql DBA 20天速成教程
  7. 【ASP.NET】ASP.NET中权限验证使用OnAuthorization实现
  8. Linux 性能监控 : CPU 、Memory 、 IO 、Network
  9. C++题目一道: 重载`-&gt;&#39;: 您真的懂成员访问运算符的重载吗?
  10. [aaronyang] nodejs学习-mongodb[1]