这里以中文英文为例.
1.spring-mvc-servlet.xml 中添加Bean
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="res"></property>
</bean>
2.创建properties文件
2.1命名规范
res_en_US.properties : res:对应以上bean的value值,en:语言种类(英语),US:代表国家
res_zh_CN.properties .
2.2 properties文件的书写
不同properties文件中有相同的key,不同的值(不同语言),如下图:
3.在jsp页面获取key值
使用 jstl 的fmt标签, 导入标签库:
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
使用标签:
<fmt:message key="welcome"></fmt:message> //key的值对应properties中的key值
4.使用IE浏览器测试多语言
浏览器默认为本地语言,如要测试使用IE浏览器,找到Internet选项-->语言-->添加....