Regarding the internationalization of SPRINGMVC, http://www.cnblogs.com/liukemng/p/3750117.html This article has already spoken very well. It says there are several ways of internationalization
1: Internationalization of header information based on HTTP (Request.getlocale ())
2: Session-based internationalization (set session Sessionlocaleresolver.locale_session_attribute_name
3: cookie-based internationalization
4: URL-based internationalization
Session-based implementation requires an entry URL or no URL is required to add a lang parameter, is not very convenient, there is no way I want to add, not add is the use of the previous local. Through the practice of URL-based internationalization to solve my problem.
Configuration applicaton.xml;
< mvc:interceptors > < bean class = "Org.springframework.web.servlet.i18n.LocaleChangeInterceptor" /> </ mvc:interceptors > < Span style= "color: #800000;" >bean id = "Localeresolver" class = "Com.sequoiadb.util.DBaasLocaleResolver" />
Ways to implement Dbaaslocaleresolver
Public classDbaaslocaleresolverextendsAcceptheaderlocaleresolver {PrivateLocale mylocale=NULL; PublicDbaaslocaleresolver () {} PublicLocale Resolvelocale (httpservletrequest request) {if(mylocale==NULL){ returnRequest.getlocale (); }Else{ returnMylocale; } } /*** I debug this class does not seem to be used *@paramRequest *@paramResponse *@paramlocale*/ Public voidSetLocale (javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Java.util.Locale Locale) {Mylocale=locale; }}
Add internationalization file
Add properties file in src directory, Chinese transcoding to use Native2ascii.exe tool, this is the JDK comes with.
In this case, the above mentioned article's URL-based internationalization code is a bit problematic, because if the null pointer exception is reported without the locale, so I changed the logic, the first time according to the browser to internationalize so use Request.getlocale (), If there is a locale parameter in the URL to return to Mylocale, the structure of this Mylocale object is not very clear to me.
The only bug is that your locale parameter filling errors will also default to using the browser to internationalize, rather than using the last locale.
The internationalization of SPRINGMVC