Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.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 MVC中更改筛选器类中的区域设置_Java_Spring_Spring Mvc - Fatal编程技术网

Java 在Spring MVC中更改筛选器类中的区域设置

Java 在Spring MVC中更改筛选器类中的区域设置,java,spring,spring-mvc,Java,Spring,Spring Mvc,如何在springMVC中更改筛选器类中的区域设置 在我的filter类中,我使用以下代码: LocaleContextHolder.setLocale(new Locale(lang)); 我正在传递lang值为“ms” 当我从UI更改区域设置时,它工作正常。我要更换过滤器,它不工作 在我的springservlet.xml中,我配置了以下内容 <bean id="localeResolver" class="org.springframework.web.servlet.i1

如何在springMVC中更改筛选器类中的区域设置

在我的filter类中,我使用以下代码:

LocaleContextHolder.setLocale(new Locale(lang));
我正在传递lang值为“ms”

当我从UI更改区域设置时,它工作正常。我要更换过滤器,它不工作

在我的springservlet.xml中,我配置了以下内容

<bean id="localeResolver"
    class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
    <property name="defaultLocale" value="en" />    
</bean>
<mvc:interceptors>
    <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName">
            <value>locale</value>
        </property>
    </bean>
</mvc:interceptors>

场所
Web.xml org.springframework.web.context.ContextLoaderListener


上下文配置位置
类路径:/conf/context/spring-platform.xml
类路径:/conf/context/spring-beans.xml
类路径:/conf/context/spring-security.xml
访问过滤器
org.springframework.web.filter.DelegatingFilterProxy
访问过滤器
/*
春天
org.springframework.web.servlet.DispatcherServlet
1.
春天
*.做
30
杰西
com.sun.jersey.spi.spring.container.servlet.SpringServlet
com.sun.jersey.api.json.POJOMappingFeature
真的
1.
杰西
/服务/*
http://www.springframework.org/tags
/参考资料/tlds/spring.tld

注意正在发生(区域设置没有改变)。日志或控制台中没有异常。

您使用的是SessionLocalerResolver,因此请尝试以下代码

Locale locale = new Locale(lang);
WebUtils.setSessionAttribute(httpRequest,SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME,locale);

它会将您的区域设置设置为会话。我想这会解决你的问题。

+1。确认它能创造奇迹。我使用的是一个CustomPreAuthenticationFilter,它在Spring Security J2EEPreAuthenticationdProcessingFilter之后立即调用。用户有一个配置文件,在该配置文件中,他可以定义首选语言(区域设置),而不管其计算机区域设置如何。这个解决方案成功了。谢谢你@Rajesh。
Locale locale = new Locale(lang);
WebUtils.setSessionAttribute(httpRequest,SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME,locale);