<spring:message />国际化

来源:互联网 发布:指甲油品牌推荐知乎 编辑:程序博客网 时间:2024/06/03 19:27

转载地址: http://blog.csdn.net/cq1982/article/details/44000955


1、在spring配置文件中添加如下配置文件

[java] view plain copy
  1. <!-- 国际化 -->  
  2. <bean id="messageSource"  
  3.     class="org.springframework.context.support.ResourceBundleMessageSource">  
  4.     <property name="basename" value="message" />  
  5. </bean>  
  6. <bean id="localeResolver"  
  7.     class="org.springframework.web.servlet.i18n.CookieLocaleResolver" />  


2、在src根目录下面新建下面两个文件

message_zh_CN.properties

hello=hello1\u4F60\u597D{0}

 

message_en_US.properties

hello=english{0}

 

3、在web目录下面新建一个jsp文件

在 页面中添加如下内容,(添加标签

[java] view plain copy
  1. <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>  

备注:uri的内容在org.springframework.web.servlet-3.1.1.RELEASE.jar包下面的META-INF/spring.tld文件

页面的编码方式,应该选用utf-8 
<%@ page language="Java"  pageEncoding="UTF-8"%> 

 

4、显示资源文件内的数据

<spring:message code="hello" arguments="111,222" argumentSeparator=",">

 

备注:arguments是用来给资源文件添加参数的,argumentSeparator是用来分割多个参数的标记 

 

5、页面显示内容

hello1你好111

原创粉丝点击