簡體   English   中英

Spring 語言環境:無法讓攔截器工作

[英]Spring locale: can't get interceptors to work

我有一個帶有 2 個鏈接的 jsp 文件,這些鏈接將屬性 lang 設置為 en 或 de。
我還有一條消息需要用相應的語言更改為英語或德語。
我有 2 個帶有代碼的屬性文件。 我為語言環境制作了配置文件。
我嘗試過不同的類和屬性組合,但我永遠無法改變消息。

這是我的代碼:

jsp文件:

Language : <a href="?lang=en">English</a>|<a href="?lang=de">German</a>
   <h3>
      <spring:message code="test" text="default text" />
   </h3>
Current Locale : ${pageContext.response.locale} ---- ${pageContext.request.locale}

applicationContext.locale.xml 文件:(這是在 applicationContext.xml 中導入的)

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">


<bean id="messageSource"
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basename" value="WEB-INF/locale/welcome" />
    <property name="cacheSeconds" value="-1" />
    <property name="defaultEncoding" value="UTF-8"/>
</bean>

<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.CookieLocaleResolver">
    <property name="defaultLocale" value="en"/>
</bean>

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    <property name="interceptors">
        <list>
            <ref bean="localeChangeInterceptor"/>
        </list>
    </property>
</bean>

我有 2 個屬性文件:welcome.properties 和welcome_de.properties。 兩者都有代碼測試和不同的值。

問題是如果我設置默認的語言環境,它總是會這樣。 如果我沒有設置它,語言環境解析器將采用請求的語言環境。

我無法將響應的語言環境設置為從 url 參數中獲取。

你有什么建議嗎?

謝謝:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM