MyFilter Myfilter com.MyFilter Myfilter /* Test com.Test Test /test
1 //这是我的自定义监听 2 import java.io.IOException; 3 4 import javax.servlet.Filter; 5 import javax.servlet.FilterChain; 6 import javax.servlet.FilterConfig; 7 import javax.servlet.ServletException; 8 import javax.servlet.ServletRequest; 9 import javax.servlet.ServletResponse;10 import javax.servlet.http.HttpServletRequest;11 12 public class MyFilter implements Filter{13 14 @Override15 public void destroy() {16 17 }18 19 @Override20 public void doFilter(ServletRequest arg0, ServletResponse arg1,FilterChain arg2) throws IOException, ServletException {21 22 HttpServletRequest request =( HttpServletRequest)arg0;23 24 25 System.out.println("----->"+request.getRequestURI());26 27 if("/MyFilter/test".equals(request.getRequestURI())){28 arg2.doFilter(arg0, arg1);29 }30 }31 32 @Override33 public void init(FilterConfig arg0) throws ServletException {34 35 }36 }37 38 39 import javax.servlet.ServletRequest;40 import javax.servlet.ServletResponse;41 import javax.servlet.http.HttpServlet;42 43 public class Test extends HttpServlet{44 45 private static final long serialVersionUID = 1L;46 47 @Override48 public void service(ServletRequest arg0, ServletResponse arg1){49 System.out.println("我是MyFilter类的测试标识");50 51 }52 }
主要是针对WEB开发的3大包装类的监听