1、在springmvc-servlet.xml配置文件里面添加下面的配置信息:
<!-- 配置需要访问的国际化资源,此处的路径配置为src目录下资源 -->
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>/resources/common</value>
<value>/resources/other</value>
<value>/resources/action</value>
</list>
</property>
</bean>
上面资源配置的资源文件目录如下:
因为springMVC会去组装需要访问的国际化资源文件路径,所以只要写资源文件的名称即可(eg. resources/common, resources/other…),但是在实际提供的国际化资源文件中需要提供文件名+语言信息(eg. common_en.properties, common_en.properties)。
2、在jsp页面头部引入下面信息:
<%@ taglib prefix="spring" uri=http://www.springframework.org/tags %>
3、 在jsp页面使用标签访问国际化资源:
<spring:message code="common.message" />