我已经为我的 Spring MVC 项目设置了 i18n。当我点击链接时,语言没有改变:
<a href="?lang=hi">Hindi</a>
<a href="?lang=en">English</a>
控制器-servlet.xml
<mvc:annotation-driven/>
<context:component-scan base-package="com.avvas.search.controller" />
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:resources/messages" />
<property name="defaultEncoding" value="UTF-8"/>
<property name="cacheSeconds" value="0" />
</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="handlerMapping"
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<ref bean="localeChangeInterceptor" />
</property>
</bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/pages/" />
<property name="suffix" value=".jsp" />
</bean>
<mvc:resources mapping="/css/**" location="/css/" />
<mvc:resources mapping="/javascript/**" location="/javascript/" />
本地更改链接:
<a href="?lang=hi">Hindi</a>
<a href="?lang=en">English</a>
问题是当我点击印地语时,页面应该以印地语显示,语言没有改变。但是,我将默认语言更改为印地语,<property name="defaultLocale" value="hi"/>
然后它将本地语言作为印地语,但是当我单击英语本地更改链接时,本地没有更改。