区域设置仅获取默认区域设置的值而其他区域设置未显示

时间:2016-10-13 05:07:31

标签: java spring spring-mvc

嗨我正在使用Spring语言环境,但是它仍然从一个语言环境中获取值而不是来自其他语言环境是我的代码到目前为止 的 DispatcherServlet的

group.id

这是我在 page.jsp

中使用的
    <mvc:annotation-driven enable-matrix-variables="true" />
<context:component-scan base-package="com.*" />
    <bean id="messageSource"
            class="org.springframework.context.support.ResourceBundleMessageSource">
            <property name="basenames">
                <list>
                    <value>/com/resources/messages_en</value>
                    <value>/com/resources/messages_nl</value>
                </list>
            </property>
            <property name="defaultEncoding" value="UTF-8" />
        </bean>
        <bean id="localeResolver"
            class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
        </bean>
        <mvc:interceptors>
            <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
                <property name="paramName" value="language" />
            </bean>
        </mvc:interceptors>

对于英语,一切正常,但点击<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%> <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title></title> </head> <body> <p> <b><h3> <a href="?language=en">English</a>| <a href="?language=nl">Dutch</a> </h3></b> </p> <spring:message code="tagline"></spring:message> <hr> </body> </html> 同时也显示英语,如何解决?

这只是我文件中的数据:

Dutch

请帮助

1 个答案:

答案 0 :(得分:0)

您的配置中是否有<mvc:annotation-driven />?您的<mvc:interceptors>也应如下所示。

 <mvc:interceptors>
     <mvc:interceptor>
        <mvc:mapping path="/**" />
          <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
              <property name="paramName" value="language" />
          </bean>
   </mvc:interceptor>
</mvc:interceptors>

和MessageSource bean

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

您的属性文件应如下所示。

messages.properties
messages_en_US.properties
messages_zh_CN.properties

检查this帖子。

相关问题