首页 > 代码库 > 【JavaEE企业应用实战学习记录】requestListener

【JavaEE企业应用实战学习记录】requestListener

 1 package sanglp.servlet; 2  3 import javax.servlet.*; 4 import javax.servlet.annotation.WebListener; 5 import javax.servlet.http.HttpServletRequest; 6  7 /** 8  * Created by Administrator on 2016/10/5. 9  */10 @WebListener11 public class RequestListener implements ServletRequestListener,ServletRequestAttributeListener {12 13     //用户请求到底,被初始化时触发该方法14     @Override15     public void requestInitialized(ServletRequestEvent servletRequestEvent) {16         HttpServletRequest request=(HttpServletRequest)servletRequestEvent.getServletRequest();17         System.out.println("发向"+request.getRequestURI()+"请求被初始化");18     }19     //用户请求到底,被销毁时触发该方法20     @Override21     public void requestDestroyed(ServletRequestEvent servletRequestEvent) {22         HttpServletRequest request=(HttpServletRequest)servletRequestEvent.getServletRequest();23         System.out.println("发向"+request.getRequestURI()+"请求被销毁");24 25     }26 27     @Override28     public void attributeAdded(ServletRequestAttributeEvent servletRequestAttributeEvent) {29         ServletContext application=servletRequestAttributeEvent.getServletContext();30         //获取添加的属性名和属性值31         String name=servletRequestAttributeEvent.getName();32         Object value=http://www.mamicode.com/servletRequestAttributeEvent.getValue();33         System.out.println(application+"范围内添加了"+name+"值为"+value+"的属性");34 35     }36 37     @Override38     public void attributeRemoved(ServletRequestAttributeEvent servletRequestAttributeEvent) {39         ServletContext application=servletRequestAttributeEvent.getServletContext();40         //获取添加的属性名和属性值41         String name=servletRequestAttributeEvent.getName();42         Object value=http://www.mamicode.com/servletRequestAttributeEvent.getValue();43         System.out.println(application+"范围内删除了"+name+"值为"+value+"的属性");44     }45 46     @Override47     public void attributeReplaced(ServletRequestAttributeEvent servletRequestAttributeEvent) {48         ServletContext application=servletRequestAttributeEvent.getServletContext();49         //获取添加的属性名和属性值50         String name=servletRequestAttributeEvent.getName();51         Object value=http://www.mamicode.com/servletRequestAttributeEvent.getValue();52         System.out.println(application+"范围内替换了"+name+"值为"+value+"的属性");53     }54 }

 

【JavaEE企业应用实战学习记录】requestListener