Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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 使用SpringMVC配置区域设置切换_Java_Spring_Spring Mvc - Fatal编程技术网

Java 使用SpringMVC配置区域设置切换

Java 使用SpringMVC配置区域设置切换,java,spring,spring-mvc,Java,Spring,Spring Mvc,首先,我必须说,我是开发Spring应用程序的绝对初学者。我试图做的是将区域设置从“en”切换到“de”。为此,我在mvc-dispatcher-servlet.xml中找到了下面的配置 <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"> <property name="basename" value="Messa

首先,我必须说,我是开发Spring应用程序的绝对初学者。我试图做的是将区域设置从“en”切换到“de”。为此,我在mvc-dispatcher-servlet.xml中找到了下面的配置

 <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
          <property name="basename" value="Messages" />
   </bean>

   <!-- Localization Start -->
   <bean id="localeResolver"
         class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
          <property name="defaultLocale" value="en" />
   </bean>

   <bean id="localeChangeInterceptor"
         class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
          <property name="paramName" value="language" />
   </bean>

   <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" >
          <property name="interceptors">
                 <list>
                        <ref bean="localeChangeInterceptor" />
                 </list>
          </property>
   </bean>

之后,我希望可以通过在现有URL后面添加“?language=de”来更改区域设置。因此请求“”应切换区域设置。这不管用。网站以定义的默认语言显示

我的属性文件位于/src/main/resources中。这些名称是“Messages\u en.properties”和“Messages\u de.properties”。如果我将默认语言切换为“de”,则会加载正确的语言文件,网站将以德语显示。
有人知道我的配置有什么问题吗?

我相信您必须在中向拦截器注册LocaleChangeInterceptor



LocaleChangeInterceptor配置为查找参数名“locale”以指示用户的区域设置的更改,并使用Spring MVC命名空间注册为拦截器。例如,将“locale=es”添加到URL会将区域设置更改为西班牙语。

如果将“.properties”-文件重命名为“.properties”,是否会更改任何内容?(可能MVC无法识别该文件,因为它包含打字错误)对不起,这是我的错误。正确的文件扩展名为“.properties”
<!-- Declare the Interceptor -->
<mvc:interceptors>    
    <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"
          p:paramName="locale" />
</mvc:interceptors>