Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring本地化在第一次点击时不起作用,在刷新时起作用。。!_Java_Spring_Spring Mvc - Fatal编程技术网

Java Spring本地化在第一次点击时不起作用,在刷新时起作用。。!

Java Spring本地化在第一次点击时不起作用,在刷新时起作用。。!,java,spring,spring-mvc,Java,Spring,Spring Mvc,当我第一次点击页面时,区域设置没有发生变化,但在刷新页面时,区域设置发生了完美的变化。我在谷歌上搜索了很多,但没有找到任何解决这种荒谬行为的方法。 下面我分享我的spring配置文件的代码 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-

当我第一次点击页面时,区域设置没有发生变化,但在刷新页面时,区域设置发生了完美的变化。我在谷歌上搜索了很多,但没有找到任何解决这种荒谬行为的方法。 下面我分享我的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>

我也有同样的问题。以下是我在mvc-dispatcher-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}
在不刷新的情况下获取区域设置