Fir*_*mir 12 spring-mvc internationalization spring-3
编辑:我的Spring框架版本3.0.5
这是一个小问题,当我点击语言转换器链接时,语言没有改变.
语言文件(messages_xx.properties)位于类路径i18n目录中.文件是:
i18n/messages_en.properties
i18n/messages_ar.properties
Run Code Online (Sandbox Code Playgroud)
弹簧配置
<!-- 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>
Run Code Online (Sandbox Code Playgroud)
JSP代码中的一节
<a href="?lang=ar"><spring:message code="header.arabic" /></a> |
<a href="?lang=en"><spring:message code="header.english" /></a>
Run Code Online (Sandbox Code Playgroud)
问题是,当我单击上面的链接来更改语言时,语言环境更改功能无效.我通过将"defaultLocate"更改为"ar"进行测试,并且我收到了阿拉伯语文本.
这可能有什么问题?tomcat日志中也没有任何内容.
Pau*_*ner 29
您必须在Spring-MVC的MVC拦截器中注册localeChangeInterceptor才能考虑它.将拦截器添加到配置中:
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang"></property>
</bean>
</mvc:interceptors>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15337 次 |
| 最近记录: |