Spring locale: can't get interceptors to work
I have a jsp file with 2 links which set a property lang to either en or de.
I also have a message that needs to be changed in the corresponding language either english or german. I have the 2 property files with the codes. I made the configuration file for the locale. I've tried different combination of classes and properties but I can never get the message changed.This is my code:
jsp file:
Language : <a href="?lang=en">English</a>|<a href="?lang=de">German</a>
<h3>
<spring:message c开发者_如何学Code="test" text="default text" />
</h3>
Current Locale : ${pageContext.response.locale} ---- ${pageContext.request.locale}
applicationContext.locale.xml file: (this is imported in applicationContext.xml)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="WEB-INF/locale/welcome" />
<property name="cacheSeconds" value="-1" />
<property name="defaultEncoding" value="UTF-8"/>
</bean>
<bean id="localeChangeInterceptor"
class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
<property name="defaultLocale" value="en"/>
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="interceptors">
<list>
<ref bean="localeChangeInterceptor"/>
</list>
</property>
</bean>
I have 2 property files: welcome.properties and welcome_de.properties. Both have a code test and different values to it.
The problem is if I set the default Locale it will always take that. If I don't set it the locale resolver will take the locale of the request.
I can't set the locale of the response to be taken from the url parameter.
Do you have any suggestions?
Thanks :)
Check your code against the project you can download from the MVC Simplifications in Spring 3.0
https://src.springframework.org/svn/spring-samples/mvc-basic/trunk/
精彩评论