随笔-9  评论-1  文章-0  trackbacks-0

经测试没问题

1>程序使用UTF-8
2>编码过虑为UTF-8      //影响post提交
3>server.xml加URIEncoding="UTF-8" //影响get提交
4>jsp页面用<%@ page pageEncoding="UTF-8"%>
5>htm页面用<meta http-equiv="content-type" content="text/html; charset=UTF-8">

注意:get提交不能直接在地址栏输入测试,要在页面里转向.

用到的配置:

<!-- web.xml -->
  
< filter >
    
< filter-name > encoding </ filter-name >
    
< filter-class > com.util.EncodingFilter </ filter-class >
    
< init-param >
      
< param-name > encoding </ param-name >
      
< param-value > UTF-8 </ param-value >
    
</ init-param >
  
</ filter >
  
< filter-mapping >
    
< filter-name > encoding </ filter-name >
    
< url-pattern > /* </ url-pattern >
  
</ filter-mapping >

 

 1 // EncodingFilter.java
 2
 3 import  java.io.IOException;
 4
 5 import  javax.servlet.Filter;
 6 import  javax.servlet.FilterChain;
 7 import  javax.servlet.FilterConfig;
 8 import  javax.servlet.ServletException;
 9 import  javax.servlet.ServletRequest;
10 import  javax.servlet.ServletResponse;
11 import  javax.servlet.http.HttpServletRequest;
12
13 public   class  EncodingFilter  implements  Filter
14 {
15      protected  FilterConfig filterConfig;
16      private  String targetEncoding  =   " UTF-8 " ;
17
18      public   void  init(FilterConfig config)  throws  ServletException  {
19          this .filterConfig  =  config;
20          this .targetEncoding  =  config.getInitParameter( " encoding " );
21     }

22
23       public   void  doFilter(ServletRequest srequest, ServletResponse  sresponse, FilterChain chain)
24          throws  IOException, ServletException  {
25         HttpServletRequest request  =  (HttpServletRequest)srequest;
26
27          if ( true ) {
28          request.setCharacterEncoding(targetEncoding);
29         }

30
31         chain.doFilter(srequest,sresponse);  
32     }
   
33
34   public   void  setFilterConfig( final  FilterConfig filterConfig) {
35          this .filterConfig = filterConfig;
36  }

37
38   public   void  destroy() {
39    this .filterConfig = null ;
40  }

41 }

42


posted on 2006-06-18 09:22 你是目标 阅读(249) 评论(0)  编辑  收藏 所属分类: JSP

只有注册用户登录后才能发表评论。


网站导航: