• (转)spring mvc 中文乱码问题解决


    在eclipse环境里,页面传输数据的时候通常用ISO-8859-1这个字符集
    可以用 str = new String(str.getBytes("ISO-8859-1"), "GBK"); 转码
    str是你页面得到的字符串,后面的表示从"ISO-8859-1"转到"GBK",或者你转成别的也可以

    16:35 浏览 (1550) 评论 (2) 分类: 技术 收藏 相关推荐 评论
    chenlb 2007-09-09 回复 
    不好意思多写了 
    Java代码 
    <filter>  
      <filter-name>Set Character Encoding</filter-name>  
      <filter-class>filters.SetCharacterEncodingFilter</filter-class>  
      <init-param>  
      <param-name>encoding</param-name>  
      <param-value>utf8</param-value>  
      </init-param>  
    </filter>  
     <filter-mapping>  
      <filter-name>Set Character Encoding</filter-name>  
      <url-pattern>/*</url-pattern>  
     </filter-mapping>  

    <filter>  
      <filter-name>Set Character Encoding</filter-name>  
      <filter-class>filters.SetCharacterEncodingFilter</filter-class>  
      <init-param>  
      <param-name>encoding</param-name>  
      <param-value>utf8</param-value>  
      </init-param>  
    </filter>  
     <filter-mapping>  
      <filter-name>Set Character Encoding</filter-name>  
      <url-pattern>/*</url-pattern>  
     </filter-mapping>  
    chenlb 2007-09-09 回复 
    如果你这样str = new String(str.getBytes("ISO-8859-1"), "GBK"); 转码。 写出来程序通用性不好,而且每次有中文都要这样,用过虑器好。但只对post方式有效。get方式看, http://www.blogjava.net/chenlb/archive/2007/07/17/130922.html 

    如果是spring 

    用spring提供的过虑器,在web.xml里加 
    Java代码 
    <filter>  
      <filter-name>Set Character Encoding</filter-name>  
      <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
      <init-param>  
      <param-name>encoding</param-name>  
      <param-value>utf8</param-value>  
      </init-param>  
    </filter>  
     <filter-mapping>  
      <filter-name>Set Character Encoding</filter-name>  
      <url-pattern>/*</url-pattern>  
     </filter-mapping>  

     <filter>
      <filter-name>Set Character Encoding</filter-name>
      <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
      <init-param>
      <param-name>encoding</param-name>
      <param-value>utf8</param-value>
      </init-param>
     </filter>
      <filter-mapping>
      <filter-name>Set Character Encoding</filter-name>
      <url-pattern>/*</url-pattern>
      </filter-mapping>


    如没用spring,用tomcat里面的例子(在webappsservlets-examplesWEB-INFclasses里把filters目录放到你的classer下,其实只要SetCharacterEncodingFilter就可以了,同样在web.xml里加 
    Java代码 
    <filter>  
      <filter-name>Set Character Encoding</filter-name>  
      <filter-class>filters.SetCharacterEncodingFilter</filter-class>  
      <init-param>  
      <param-name>encoding</param-name>  
      <param-value>utf8</param-value>  
      </init-param>  
    </filter>  
     <filter-mapping>  
      <filter-name>Set Character Encoding</filter-name>  
      <url-pattern>/*</url-pattern>  
     </filter-mapping>  
    http://xhy0422.javaeye.com/blog/51084

  • 相关阅读:
    MySQL主从复制与主主复制
    Go语言mgo
    beego07----web博客
    mongo14-----group,aggregate,mapReduce
    mongo13----application set与分片结合
    mongo12---手动预先分片
    TCP/IP详解学习笔记(4)-ICMP协议,ping和Traceroute
    TCP/IP详解学习笔记(3)-IP协议,ARP协议,RARP协议
    TCP/IP详解学习笔记(2)-数据链路层
    TCP/IP详解学习笔记(1)-基本概念
  • 原文地址:https://www.cnblogs.com/u0mo5/p/4100929.html
Copyright © 2020-2023  润新知