Spring LocaleChangeInterceptor

You can enable changing of locales by adding the  LocaleChangeInterceptor  to one of the handler mappings (see Section 16.4, “Handler mappings”). It will detect a parameter in the request and change the locale. It calls  setLocale()  on the  LocaleResolver  that also exists in the context. 
       The following example shows that calls to all  *.view  resources containing a parameter named  siteLanguage  will now change the locale. So, for example, a request for the following URL,  http://www.sf.net/home.view?siteLanguage=nl  will change the site language to Dutch.
<bean id="localeChangeInterceptor"
        class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
        <property name="paramName" value="siteLanguage"/>
</bean>

<bean id="localeResolver"
        class="org.springframework.web.servlet.i18n.CookieLocaleResolver"/>

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

좋은 웹페이지 즐겨찾기