过滤器,监听器

Filter

创建——implements javax.servlet.Filter

@WebFilter(filterName="名",urlPatterns={"路径1","路径2","路径3","路径4"..........})

实现接口三个方法——init();doFilter();destory();

doFilter(ServletRequest req,ServletResponse resp,FilterChain chain);

获取URI——HttpServletRequest request=(HttpServletRequest)req      String uri=request.getRequestURI();

多个filter执行顺序——xml文件内有则按照xml顺序执行,否则按照字母表顺序执行

Listener

创建——implements ServletContextListener,HttpSessionListener,HttpSessionAttributeListener

监听三个对象——ServletContext,HttpSession,ServletRequest

值的改变——implements HttpSessionBindingListener

你可能感兴趣的:(过滤器,监听器)