//和一般的servlet一样可以获得初始参数 public void init(FilterConfig config)throws ServletException { this.filterConfig=config; this.targetEncoding=config.getInitParameter("encoding"); System.out.println("!!!!request is encoded in "+targetEncoding); }
//过滤功能在此处实现 public void doFilter(ServletRequest req,ServletResponse res,FilterChain chain) throws IOException,ServletException{ //follow line is for debug helping //System.out.println("!!!!request is encoded in ** "+targetEncoding); HttpServletRequest request=(HttpServletRequest)req; request.setCharacterEncoding(this.targetEncoding); //turn the operation right to the next filter chain.doFilter(req, res); }
public void serFilterConfig(final FilterConfig filterConfig){ this.filterConfig=filterConfig; } public void destroy(){ this.filterConfig=null; } }
//title: filter for transform encoding method to gb2312 //Note:部署filter包含两部分:指定类名、filter名及初始化参数; // 指定filter的映射及作用范围(目录)
//和一般的servlet一样可以获得初始参数 public void init(FilterConfig config)throws ServletException { this.filterConfig=config; this.targetEncoding=config.getInitParameter("encoding"); System.out.println("!!!!request is encoded in "+targetEncoding); }
//过滤功能在此处实现 public void doFilter(ServletRequest req,ServletResponse res,FilterChain chain) throws IOException,ServletException{ //follow line is for debug helping //System.out.println("!!!!request is encoded in ** "+targetEncoding); HttpServletRequest request=(HttpServletRequest)req; request.setCharacterEncoding(this.targetEncoding); //turn the operation right to the next filter chain.doFilter(req, res); }
public void serFilterConfig(final FilterConfig filterConfig){ this.filterConfig=filterConfig; } public void destroy(){ this.filterConfig=null; } }