Spring MVC是通过实现了LocaleResolver的类来识别用户的locale
1. org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver
默认的locale resolver 他是通过提取request.header的'Accept-Language'的值来解析
2. org.springframework.web.servlet.i18n.SessionLocaleResolver
Another option of resolving locales is by SessionLocaleResolver. It resolves locales by inspecting
a predefined attribute in a user’s session. If the session attribute doesn’t exist, this locale
resolver will determine the default locale from the accept-language HTTP header.
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="en" />
</bean>
You can set the defaultLocale property for this resolver in case the session attribute
doesn’t exist. Note that this locale resolver is able to change a user’s locale by altering the
session attribute that stores the locale.
3. org.springframework.web.servlet.i18n.CookieLocaleResolver
You can also use CookieLocaleResolver to resolve locales by inspecting a cookie in a user’s
browser. If the cookie doesn’t exist, this locale resolver will determine the default locale from
the accept-language HTTP header.
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver" />
The cookie used by this locale resolver can be customized by setting the cookieName and
cookieMaxAge properties. The cookieMaxAge property indicates how many seconds this cookie
should be persisted. The value -1 indicates that this cookie will be invalid after the browser is
closed.
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="cookieName" value="language" />
<property name="cookieMaxAge" value="3600" />
<property name="defaultLocale" value="en" />
</bean>
You can also set the defaultLocale property for this resolver in case the cookie doesn’t
exist in a user’s browser. This locale resolver is able to change a user’s locale by altering the
cookie that stores the locale.
分享到:
相关推荐
Spring MVC 国际化的配置方法及使用,希望能对大家的学习、工作有帮助。
springmvc使用注解的方式,进行国际化。
6.Spring MVC 国际化案例 7.Spring MVC 请求转发与请求重定向案例 8.Spring MVC 下载 Excel 文档的需求案例 9.Spring MVC RESTful 风格的请求方式案例 10.Spring + Spring MVC + JDBCTemplate 整合并通过 RESTful ...
全书共计12章,分别从Spring框架、模型2和MVC模式、Spring MVC介绍、控制器、数据绑定和表单标签库、传唤器和格式化、验证器、表达式语言、JSTL、国际化、上传文件、下载文件多个角度介绍了Spring MVC。除此之外,...
全书共计12章,分别从Spring框架、模型2和MVC模式、Spring MVC介绍、控制器、数据绑定和表单标签库、传唤器和格式化、验证器、表达式语言、JSTL、国际化、上传文件、下载文件多个角度介绍了Spring MVC。除此之外,...
真正可以使用的 spring mvc 2.5.6 国际化 实例 internationalization example 实际eclipse工程,包含jar包。 http://localhost:8080/welcome.htm
采用spring技术 实现项目中英文切换 国际化
全书共计12章,分别从Spring框架、模型2和MVC模式、Spring MVC介绍、控制器、数据绑定和表单标签库、传唤器和格式化、验证器、表达式语言、JSTL、国际化、上传文件、下载文件多个角度介绍了Spring MVC。除此之外,...
包含国际化、标签、Theme、视图展现的FreeMarker、JasperReports、Tiles、Velocity、XSLT相关类。 当然,如果你的应用使用了独立的MVC框架,则无需这个JAR文件里的任何类。(例如: org.springframework.web....
一个简单的基于Maven 3 和 Spring mvc 3 框架搭建的国际化网站雏形。 spring mvc 入门配置 国际化配置 易扩展。 error_messages_en.properties error_messages_zh.properties 没有库文件,maven配好了会自动加载库...
全书共计12章,分别从Spring框架、模型2和MVC模式、Spring MVC介绍、控制器、数据绑定和表单标签库、传唤器和格式化、验证器、表达式语言、JSTL、国际化、上传文件、下载文件多个角度介绍了Spring MVC。除此之外,...
springmvc配置国际化实例,超简单,下载即可用,欢迎下载
myeclipse 通用版 国际化插件 ResourceBundleEditor_v0.7.7 只要解压后覆盖原来的即可!
如何对错误信息进行国际化(2) 目录 数据模型访问结构 访问数据模型:ModelAndView 访问数据模型:@ModelAttribute 访问数据模型:Map及Model 访问数据模型:@SessionAttributes 一场由@SessionAttributes引发的血案.....
spring mvc 深入总结,文章是转载拷贝而来,谢谢原作者!
Spring MVC是Spring框架中的一部分,全称是Spring Web MVC,主要用于实现MVC设计模式的Web框架。它分离了控制器、模型对象、过滤器以及处理程序...此外,Spring MVC还支持本地化/国际化(Locale)解析及文件上传等。
全书共计12章,分别从Spring框架、模型2和MVC模式、Spring MVC介绍、控制器、数据绑定和表单标签库、传唤器和格式化、验证器、表达式语言、JSTL、国际化、上传文件、下载文件多个角度介绍了Spring MVC。除此之外,...
Spring2.5的国际化配置 基于浏览器语言的国际化配置 使用Spring的MVC,并且配置中有配置Resource文件 <!-- 资源文件绑定器 --> <bean id="messageSource" class="org.springframework.context.support....