springmvc 国际化

1、配置文件applicationContex.xml

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">   
        <property name="basename" value="messages"/>  
       </bean>   
    <!-- 获取本地 -->  
    <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver"/> 

2、新建配置文件messages_zh_CN.properties 放到到resources目录中,注意 这里的文件名称中messages要和上面配置文件中的 value="messages" 保持一致,_zh_CN 代表中国中文,_en_US 代表美国英语,是不可以改变的。文件内容如下

title=u4F60u597Du554A

3、jsp页面中使用

<%@ page language="java"  pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>  
<%@ taglib prefix="spring" uri="/WEB-INF/spring.tld"%>
  
<html>  
<head>  
<title>Reservation Form</title>  

<style>  
.error {  
    color: #ff0000;  
    font-weight: bold;  
}  
</style>  
</head>  
  
<body>  
  
                <spring:message code="title"/>  
               
      
</body>  
</html> 

注意:spring.tld 文件一般是在webmvc.jar里面需要复制出来放到WEB-INF目录下

原文地址:https://www.cnblogs.com/lvlv/p/4916599.html