2014-12-03 28 views
2

當我第一次點擊頁面時,語言環境變化沒有發生,但是在刷新語言環境時完全改變。我搜索了很多,但沒有找到任何解決這個荒謬的行爲。 下面我分享我的spring配置文件的代碼。春季本地化不能在第一次打擊,刷新它工作..!

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.1.xsd 
    http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd 
    "> 

    <bean id="localeChangeInterceptor" 
     class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"> 
     <property name="paramName" value="lang" /> 
    </bean> 
    <mvc:interceptors> 
     <ref bean="localeChangeInterceptor" /> 
    </mvc:interceptors> 

    <bean id="messageSource" 
     class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
     <property name="basename" value="classpath:i18/messages" /> 
     <property name="defaultEncoding" value="UTF-8" /> 
    </bean> 


    <bean id="localeResolver" 
     class="org.springframework.web.servlet.i18n.CookieLocaleResolver"> 
     <!-- <property name="defaultLocale" value="en" /> --> 
     <property name="cookieName" value="springlang"/> 
    </bean> 

    <bean id="handlerMapping" 
     class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"> 
     <property name="interceptors"> 
      <ref bean="localeChangeInterceptor" /> 
     </property> 
    </bean> 

</beans> 

回答

0

我有同樣的問題。下面是我在MVC-調度-servlet.xml的代碼:

<mvc:interceptors> 
    <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"> 
     <property name="paramName" value="language"/> 
    </bean> 
</mvc:interceptors> 
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver"> 
    <property name="defaultLocale" value="fr" /> 
    <property name="cookieName" value="lang"/> 
    <property name="cookieMaxAge" value="2147483647" /> 
</bean> 

在我的JSP中,我必須使用${pageContext.response.locale}得到的語言環境不刷新。

相關問題