JSP页面传值乱码过滤方法

本文实例讲述了JSP页面传值乱码过滤方法。分享给大家供大家参考,具体如下:

1.过滤器类:

package com.token.t1;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class CharacterEncodingFilter implements Filter {
  public void destroy() {
  }
  public void doFilter(ServletRequest request, ServletResponse response,
      FilterChain chain) throws IOException, ServletException {
     request.setCharacterEncoding("gbk");
    chain.doFilter(request, response);
  }
  public void init(FilterConfig arg0) throws ServletException {
  }
}

2.xml文件配置:




  
    CharacterEncodingFilter   
    com.token.t1.CharacterEncodingFilter
  
  
    CharacterEncodingFilter
     /* 
  
  
  
    index.jsp
  


当我用

的默认提交方式提交时,此方法过滤不了,需要设置 method="post",才可以过滤

希望本文所述对大家JSP程序设计有所帮助。

你可能感兴趣的:(JSP页面传值乱码过滤方法)