springMVC <spring:message>国际化

来源:互联网 发布:php unlink删除文件 编辑:程序博客网 时间:2024/05/30 05:30

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

[java] view plain copy 在CODE上查看代码片派生到我的代码片<!-- 国际化 -->  <bean id="messageSource"      class="org.springframework.context.support.ResourceBundleMessageSource">      <property name="basename" value="message" />  </bean>  <bean id="localeResolver"      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 在CODE上查看代码片派生到我的代码片

<%@ 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

0 0
原创粉丝点击