spring 国际化

见spring官方 DEMO:mvc-basic

1。在spring Bean 配置中加入

<!-- Configures Handler Interceptors -->
<mvc:interceptors>
<!-- Changes the locale when a 'locale' request parameter is sent; e.g. /?locale=de -->
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
</mvc:interceptors>


<!-- Saves a locale change using a cookie -->
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver" />


<!-- Application Message Bundle -->
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="/WEB-INF/messages/messages" /> //配置文件的位置,如“messages_de.properties”的位置
<property name="cacheSeconds" value="0" />
</bean>

2。jsp页面

<a href="?locale=en_us">us</a> |  <a href="?locale=zh_cn">gb</a> | <a href="?locale=es_es">es</a> | <a href="?locale=de_de">de</a>


en_us :代表英文  对应的文件为 messages_en.properties

zh_cn :代表中文   对应的文件为 messages_zh.properties

es_es : 代表西班牙文  对应的文件为 messages_es.properties

de_de : 代表德文 。对应的文件为 messages_de.properties


PS: 这样传过去(即在根路径下直接传个locale过去)的 locale spring 会自动和 response中的 locale 关联起来!

${pageContext.response.locale}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值