编码过滤器 package cn.cx.filter;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
package cn.cx.filter; 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; import javax.servlet.http.HttpServletRequest; public class NewFilter implements Filter { private String CharSet = null; @Override public void destroy() { System.out.println(" 销毁 !"); } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest)request; HttpServletResponse resp = (HttpServletResponse)Response; req.setCharacterEncoding(this.CharSet); System.out.println("doFilter()执行之前!"); chain.doFilter(request, response);//下传页面 激活下一个过滤器 System.out.println("doFilter()执行之后!"); } @Override public void init(FilterConfig config) throws ServletException { this.CharSet = config.getInitParameter("CharSet"); System.out.println("初始化成功 !"); } }