Spring locale:无法让拦截器工作

时间:2011-08-17 14:47:25

标签: java spring configuration locale

我有一个带有2个链接的jsp文件,它将属性lang设置为en或de。
我还有一条消息,需要用相应的语言(英语或德语)进行更改 我有2个属性文件与代码。我为区域设置制作了配置文件 我尝试了不同的类和属性组合,但我永远不会改变消息。

这是我的代码:

jsp文件:

Language : <a href="?lang=en">English</a>|<a href="?lang=de">German</a>
   <h3>
      <spring:message code="test" text="default text" />
   </h3>
Current Locale : ${pageContext.response.locale} ---- ${pageContext.request.locale}

applicationContext.locale.xml文件:(这是在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>

我有2个属性文件: welcome.properties和welcome_de.properties。两者都有代码测试和不同的值。

问题是,如果我设置默认的Locale,它将始终采用它。如果我没有设置它,语言环境解析器将采用请求的语言环境。

我无法设置从url参数中获取的响应的语言环境。

你有什么建议吗?

谢谢:)

1 个答案:

答案 0 :(得分:0)

相关问题