1:需要org.springframework.context.support-3.0.5.RELEASE.jar包
2:国际化的properties文件,中英文各一份
3:Spring配置文件中要配置
<!-- 国际化start-->
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource" lazy-init="false"> <property name="basenames"> <list> <!-- 加载国际化配置文件有几种语言就写几个配置文件 --> <!-- 格式: internalization_en_US.properties internalization_zh_CN.properties--> <value>classpath:i18n/internalization</value> </list> </property> <property name="defaultEncoding" value="UTF-8" /> </bean> <!-- 通过参数改变语言,可以在地址后面加上 ?language=zh_CN或?language=en_US改变 --> <bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" lazy-init="false"> <property name="paramName" value="language" /> </bean> <!-- 设置一个默认的语言 --> <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver" lazy-init="false"> <property name="defaultLocale" value="zh_CN" /> </bean> <bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" lazy-init="false"> <property name="interceptors"> <list> <ref bean="localeChangeInterceptor" /> </list> </property> </bean> <!-- 国际化end -->4:jsp页面上调用首先要导入一个标签
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
5:在页面在需要显示文字的地方
<spring:message code="first.demo"/>
6:first.demo是在properties文件中定义的
properties文件中的内容是以"键-值"形式写: first.demo=XXX