1. 程式人生 > >SpringMVC系列(八)國際化

SpringMVC系列(八)國際化

enc undle charset ucc tid utf pre 獲取值 -c

1.在pom.xml引入國際化需要的依賴

1 <!--國際化相關依賴 begin  -->
2     <dependency>
3       <groupId>jstl</groupId>
4       <artifactId>jstl</artifactId>
5       <version>1.2</version>
6     </dependency>
7 <!--國際化相關依賴 end  -->

2.在success.jsp裏面添加jstl的fmt

1 <%
@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

3.在springmvc.xml裏面國際化資源文件

1 <!-- 配置國際化資源文件 -->
2     <bean id="messageSource"
3         class="org.springframework.context.support.ResourceBundleMessageSource"
> 4 <property name="basename" value="i18n"></property> 5 </bean>

4.src/main/java新建國際化資源文件

i18n.properties

1 i18n.username=Username
2 i18n.password=Password

i18n_zh_CN.properties

1 i18n.username=\u7528\u6237\u540D
2 i18n.password=\u5BC6\u7801

i18n_en_US.properties

1
i18n.username=Username 2 i18n.password=Password

5.在success.jsp頁面通過jstl的標簽獲取值

1 <!--國際化 begin  -->
2 <p><b>國際化 begin</b></p>
3 <fmt:message key="i18n.username"></fmt:message>
4 <br>
5 <fmt:message key="i18n.password"></fmt:message>
6 <p><b>國際化 end</b></p>    
7 <!--國際化 end  -->

技術分享

SpringMVC系列(八)國際化