Подтвердить что ты не робот

Spring Изменение MVC 3 с использованием ссылки, не работающей

Изменить: My Spring фреймворк версии 3.0.5

Небольшая проблема здесь. Язык не меняется, когда я нажимаю ссылку на изменение языка.

Языковые файлы (messages_xx.properties) находятся в каталоге ipath пути classpath. Файлы:

i18n/messages_en.properties
i18n/messages_ar.properties

Spring Конфигурация

<!-- Component scanner. This is used to automatically find Spring annotations like @Service and @Repository -->
    <context:component-scan base-package="com.keype" />

    <!-- Annotation driven programming model -->
    <mvc:annotation-driven />   
    <context:annotation-config />
    <mvc:resources mapping="/static/**" location="/static/" />


    <!-- Session Object Configuration -->
    <bean id="session" class="com.keype.system.Session" scope="session">
        <aop:scoped-proxy />
    </bean>

    <!-- The View Resolver -->
    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/jsp/"
          p:suffix=".jsp"
          />

    <!-- i18n Configuration. Default language is english. Change language using ?language=en -->
    <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName" value="lang" />
    </bean>

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

    <!-- Message text files. This is set UTF-8 to display Arabic UTF correctly. -->    
    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:i18n/messages" />
        <property name="defaultEncoding" value="UTF-8"/>
    </bean>

Раздел из кода JSP

<a href="?lang=ar"><spring:message code="header.arabic" /></a> | 
    <a href="?lang=en"><spring:message code="header.english" /></a> 

Проблема заключается в том, что при нажатии этой ссылки для изменения языка функция изменения языка не работает. Я проверил, изменив "defaultLocate" на "ar", и я получаю арабский текст.

Что здесь может быть неправильным? В журнале tomcat ничего нет.

4b9b3361

Ответ 1

Вам необходимо зарегистрировать localeChangeInterceptor среди перехватчиков MVC для Spring -MVC, чтобы рассмотреть его. Добавьте перехватчик в конфигурацию:

<mvc:interceptors>  
        <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
              <property name="paramName" value="lang"></property>
        </bean>
</mvc:interceptors>

Ответ 2

                

<mvc:interceptors>
    <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"
        p:paramName="lang" />
</mvc:interceptors>

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

Ответ 3

Другая вещь, которая может помочь другим:

В моем случае, я ДОЛЖЕН добавить в applicationContext.xml. Помещая его в spring -сервер (рефлектор), не работал вообще.