您的位置:首页 > 编程语言 > Java开发

SpringMVC 国际化

2016-04-08 22:29 323 查看
web.xml
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
 
 
applicationContext.xml
 
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>format</value>
<value>exceptions</value>
<value>windows</value>
</list>
</property>
<!-- 如果在国际化资源文件中找不到对应代码的信息,就用这个代码作为名称  -->
<property name="useCodeAsDefaultMessage" value="true" />
</bean>
在src文件夹下面建立  format.properties  exception.properties window.properties 三个资源文件()
 
index.jsp
<pre class="html" name="code"><%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<html>
<head>
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
Spring mvc 国际化: <spring:message  code="name"></spring:message>
</body>
</html>



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: