Java 春天的本地解算器

Java 春天的本地解算器,java,spring,spring-mvc,internationalization,Java,Spring,Spring Mvc,Internationalization,我正在为我的应用程序使用会话区域设置解析器。我在下拉列表中显示语言。如果用户选择任何语言,则重新填充该语言中的所有值 <property name="interceptors"> <list> <ref bean="localeChangeInterceptor" /> </list> </property> <bean id="localeChangeInterceptor" cla

我正在为我的应用程序使用会话区域设置解析器。我在下拉列表中显示语言。如果用户选择任何语言,则重新填充该语言中的所有值

<property name="interceptors">
    <list>
        <ref bean="localeChangeInterceptor" />
    </list>
</property>

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

<bean id="localeResolver"
      class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />

但它并不是在会议上阅读。它始终考虑浏览器设置中的默认语言。
请对此提供帮助。

您需要通过以下方式获取区域设置:

Locale loc=RequestContextUtils.getLocale(request);

在Spring4.0中,我们还可以使用
LocaleContextResolver.getLocale()
方法。

如何检查会话中是否设置了本地设置?当用户选择新的区域设置并提交页面时,是否向URL添加了正确的请求参数?在本例中,您指定了languageCode的参数名。因此,请求URL应该类似于如果控制器方法用@RequestMapping注释,那么您只需向该方法添加一个Locale参数,Spring就会自动为您提供它@凯文·斯特姆布里奇:我只想声明,直接从会话中获取语言环境是一个好主意当然,参数方法比我写的要好得多。