Stuts 中涉及编码配置相关 ..

  // 1.在jsp页面统一设定字符编码 .
 
  
  1. <%@ page language=”java” contentType=”text/html; charset=GBK” 
  2.     pageEncoding=”GBK”%> 
  3. <%@ taglib prefix=”s” uri=”/struts-tags”%> 
  4. <!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd“> 
  5. <html> 
  6. <head> 
  7. <meta http-equiv=”Content-Type” content=”text/html; charset=GBK> 

  // 2. St ruts.properties 或在struts_config.xml文件下添加

 struts.locale=zh_CN
 struts.i18n.encoding=GBK


 // 3. 在web.xml加个filter

 
 
  
  1. <!-- zh-cn encoding --> 
  2. <filter> 
  3. <filter-name>struts-cleanup</filter-name> 
  4. <filter-class> 
  5. org.apache.struts2.dispatcher.ActionContextCleanUp 
  6. </filter-class> 
  7. </filter> 
  8. <filter-mapping> 
  9. <filter-name>struts-cleanup</filter-name> 
  10. <url-pattern>/*</url-pattern> 
  11. </filter-mapping> 

 // 4. 在Action类 添加HttpServletContext (今天问题就靠这个解决了)

 
 
  
  1. HttpServletResponse response = null
  2. response = ServletActionContext.getResponse(); 
  3. request.setCharacterEncoding("utf-8"); 
  4. response.setContentType("text/html;charset=utf-8"); 

 // 5. get方式提交的乱码问题
 
 
  
  1. String name = null
  2. name = new String(name.getBytes("iso--8859-1"),"utf-8"); 
  3. 还有Tomcat 5.x 的那个版本出现码问题 纠结的N久 换成6.0 over 搞定。 
  4.  <Connector port="80" maxHttpHeaderSize="8192" 
  5. maxThreads="150" minSpareThreads="25" maxSpareThreads="75" 
  6. enableLookups="false" redirectPort="8443" acceptCount="100" 
  7. connectionTimeout="20000" disableUploadTimeout="true"URIEncoding="GBK"/>