Spring MVC的默认区域设置和区域设置更改不起作用


问题内容

我是一名新的Spring开发人员,试图开发支持两​​种语言的示例Web应用程序。我想将默认语言环境设置为阿拉伯语言,并在用户单击JSP页面中的所需语言时更改语言环境。

这是我的mvc-dispatcher-servlet.xml,

<!-- Enables the Spring MVC @Controller programming model -->
<mvc:annotation-driven/>

<!-- Handles HTTP GET requests for /resources/** by efficiently serving 
    up static resources in the ${webappRoot}/resources directory -->
<mvc:resources mapping="/resources/**" location="/resources/" />
<context:component-scan base-package="com.benchmark.ushers.presentation.controller"/>

<bean id="internalResourceResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/pages/"/>
    <property name="suffix" value=".jsp"/>
</bean>

<!-- resource bundle  configuration-->
<bean id="messageSource"
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basename" value="classpath:locale/messages" />
    <property name="fallbackToSystemLocale" value="false"/>
    <property name="defaultEncoding" value="UTF-8"/>
</bean>

<bean id="localeResolver"
    class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
    <property name="defaultLocale" value="ar" />
</bean>

<mvc:interceptors>  
    <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
          <property name="paramName" value="lang"></property>
    </bean>
</mvc:interceptors>
<!-- end of resource bundle  configuration-->

我的JSP页面如下

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>

<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>

<tiles:insertDefinition name="defaultTemplate">

    <tiles:putAttribute name="body">







        <div class="body">

            <h1>Ushers</h1>



            lang : <a href="?lang=en">English</a> | <a

                href="?lang=ar">Arabic</a>



            <h3>

                welcome.springmvc :

                <spring:message code="footer.content" text="default text" />

            </h3>



            <h3>

                hello :

                <spring:message code="footer.hello" text="default text" />

            </h3>





        </div>







    </tiles:putAttribute>

</tiles:insertDefinition>

我不知道我的代码有什么问题,而仅显示英文文本。


问题答案:

问题中的上述配置是正确的。问题出在web.xml文件中请求的页面集作为欢迎页面,因此无需任何拦截器即可执行它。

在web.xml中注释此部分后,一切正常

<!--  <welcome-file-list>

        <welcome-file>/WEB-INF/pages/adminHome.jsp</welcome-file>

</welcome-file-list>-->