spring国际化

1 需要的jar包

spring国际化_第1张图片


2 整个应用目录图

spring国际化_第2张图片


3 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
	
	
	<context-param>  
  		<param-name>contextConfigLocation</param-name>  
  		<param-value>  
   			classpath:/spring/xml/applicationContext.xml
  		</param-value>  
 	</context-param>  
	
    <listener>  
       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
    </listener> 
	
	
	
	
	
	
  <display-name></display-name>	
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>


 
 


4  applicationContext.xml

spring国际化_第3张图片


<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> 
<beans> 
 
   <bean id="messageSource"  class="org.springframework.context.support.ResourceBundleMessageSource">  
   		<property name="basename" value="messages"/>  
   </bean>  
    
</beans> 


5 properties 文件必须放在src下面

messages_en.properties文件内容

main.title=Hello World\!


6 index.jsp

<%@ page language="java"  pageEncoding="UTF-8"%>  
<%@ taglib prefix="spring" uri="WEB-INF/lib/spring/spring.tld" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
<html>  
  <head>  
    <title>Spring国际化</title>  
  </head>  
  <body>  
   
    <spring:message code="main.title" /><br>  
 
  </body>   
  
</html>  
 



你可能感兴趣的:(spring国际化)