1. 程式人生 > >一個解決JSP中文亂碼的過濾器

一個解決JSP中文亂碼的過濾器


protected String encoding=null;
protected FilterConfig filterConfig=null;
protected boolean ignore=true;

public void destroy(){
 this.encoding=null;
 this.filterConfig=null;


public void doFilter(ServletRequest request,ServletResponseresponse,FilterChain chain)
             throwsIOException,ServletException{

           if(ignore||(request.getCharacterEncoding()==null)){

              Stringencoding=selectEncoding(request);
              if(encoding!=null)
                       request.setCharacterEncoding(encoding);
}

chain.doFilter(request,response);