Spring本地化的问题:无法切换语言



我的应用程序有这个Spring配置,如下所示

<mvc:interceptors>
    <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName" value="lang"/>
    </bean>
</mvc:interceptors>
<bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
      id="messageSource"
      p:basename="resources/l18n/label"/>
<bean
        class="org.springframework.web.servlet.i18n.CookieLocaleResolver"
        id="localeResolver"
        p:cookieName="locale"
        p:defaultLocale="en"/>

当我运行我的应用程序时,默认的lang总是ru,尽管我设置了en(p:defaultLocale="en"),当我在?lang=en上更改后缀我的URL时,一切都没有改变,一切都是ru。当我试图删除label_ru时,我得到了以下示例:org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: javax.servlet.jsp.JspTagException: No message found under code 'jumbotron.h1' for locale 'ru'

Web.xml:

<web-app id="WebApp_ID" version="2.4"
         xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>Phone Book</display-name>
    <welcome-file-list>
        <welcome-file>/WEB-INF/views/index.jsp</welcome-file>
    </welcome-file-list>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/servlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping> 

为了避免这个问题,你应该不要在web.xml文件上使用下面的标签

<welcome-file-list>
        <welcome-file>/WEB-INF/views/index.jsp</welcome-file>
    </welcome-file-list>

相关内容

  • 没有找到相关文章

最新更新