zoukankan      html  css  js  c++  java
  • Spring的国际化(转载)

    1:在MyEclipse下面创建一个test的Web  Project,然后添加Spring相关的文件,在src根目录下创建applicationContext.xml文件。 

    applicationContext.xml

    <?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>
     
           <bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver"/>
       
    </beans> 
    

    2:在src根目录下面创建4个资源文件:分别是 

    messages_zh.properties 
    main.title=你好 
    
    messages_en.properties 
    main.title=Hello World! 
    
    messages_ja.properties 
    main.title=こんにちは 
    
    messages_ko.properties 
    main.title=안녕하십니까
    

    3:在WebRoot根目录下面创建test.jsp 

    <%@ page language="java"  pageEncoding="UTF-8"%>
    <%@ taglib prefix="spring" uri="WEB-INF/lib/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>
    
        <input type="button" value="<spring:message code="main.title" />"/><br>
    
      </body> 
    
    </html>
    

    4:修改WEB-INF下面的web.xml

    <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>
       classpath*:/applicationContext*,classpath*:META-INF/applicationContext*.xml
      </param-value>
     </context-param>
     <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
     </listener>
    

      这样用Spring国际化的Test.jsp页面就做好了:),此种方法是自动默认当前用户的语言,比如客户端是日语系统,就自动寻找messages_ja.properties资源文件,是英语系统,就自动寻找messages_en.properties资源文件。 


    注意事项: 
    1:用hibernate3.0,连接Mysql5.0数据库。 

    如果用hibernate.properties配置文件 
    hibernate.connection.url jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8 

    如果用hibernate.cfg.xml配置文件 
    jdbc:mysql://localhost:3306/test?useUnicode=true&amp;useUnicode=true&amp;characterEncoding=utf-8&amp;mysqlEncoding=utf8 


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


    3:创建的数据库的编码方式也应该选用utf-8,以及表,字段的编码方式都应选用utf-8 

    注意以上3点就可以解决国际化时,所出现的页面显示乱码问题,以及插入韩语时,出现的data too long for column问题. 

  • 相关阅读:
    双谷人才财务管理(3)
    远程服务器上个人目录下python路径设置
    ubnutu16安装谷歌浏览器
    一个数组除了一个元素只出现一次,其他元素全都出现了三次,输出出现一次的元素
    一个整型数组里除了一个数字之外,其它的数字都出现了两次。请写程序找出这个只出现一次的数字。要求时间复杂度是O(n),空间复杂度是O(1)。
    滑动窗口的最大值
    360
    拼多多2018/8/5算法工程师笔试
    最小的K个数 C++(BFPRT,堆排序)
    CCF201312-3 最大的矩形(100分)
  • 原文地址:https://www.cnblogs.com/toSeeMyDream/p/4106291.html
Copyright © 2011-2022 走看看