过滤器的简单示例
1、核心配置
public class CountFilter implements javax.servlet.Filter{ServletContext sc = null;public void destroy() {}public void doFilter(ServletRequest request, ServletResponse response,FilterChain chain) throws IOException, ServletException {int count = 0;String i = Integer.toString(count);HttpServletRequest req = (HttpServletRequest)request;HttpSession session = req.getSession();session.setAttribute("count", i);System.out.println("---------"+count);chain.doFilter(request, response);}public void init(FilterConfig filterConfig) throws ServletException {sc = filterConfig.getServletContext();}}