utf-8项目血泪史

1.inputstrem和string转换时切记带上编码,如:
IOUtils.toString(inputStream, "utf-8");
 
2.string和byte[]转换时切记带上编码,如:
DigestUtils.md5Hex(sb.toString().getBytes("utf-8")).toUpperCase();
 
3.url编码解码时候要注意编码,如:
URLEncoder.encode("中文""utf-8");
 
4.使用httpclient post传中文时候,对各字段编码,如:
StringPart tempPart new StringPart(entry.getKey(), (String) entry .getValue(), "utf-8");
 
5.web.xml里对所有的http输入输出做filter编码, 如:
  1. <filter>  
  2.     <filter-name>encoding</filter-name>  
  3.     <filter-class>  
  4.         org.springframework.web.filter.CharacterEncodingFilter   
  5.     </filter-class>  
  6.     <init-param>  
  7.         <param-name>forceEncoding</param-name>  
  8.         <param-value>true</param-value>  
  9.     </init-param>  
  10.     <init-param>  
  11.         <param-name>encoding</param-name>  
  12.         <param-value>UTF-8</param-value>  
  13.     </init-param>  
  14. </filter>  
  15. <filter-mapping>  
  16.     <filter-name>encoding</filter-name>  
  17.     <url-pattern>/*</url-pattern>  
  18. </filter-mapping> 
posted @ 2011-06-23 10:56  跳刀的兔子  阅读(345)  评论(0编辑  收藏  举报