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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 @WebListener
11 public class RequestListener implements ServletRequestListener,ServletRequestAttributeListener {
12 
13     //用户请求到底,被初始化时触发该方法
14     @Override
15     public void requestInitialized(ServletRequestEvent servletRequestEvent) {
16         HttpServletRequest request=(HttpServletRequest)servletRequestEvent.getServletRequest();
17         System.out.println("发向"+request.getRequestURI()+"请求被初始化");
18     }
19     //用户请求到底,被销毁时触发该方法
20     @Override
21     public void requestDestroyed(ServletRequestEvent servletRequestEvent) {
22         HttpServletRequest request=(HttpServletRequest)servletRequestEvent.getServletRequest();
23         System.out.println("发向"+request.getRequestURI()+"请求被销毁");
24 
25     }
26 
27     @Override
28     public void attributeAdded(ServletRequestAttributeEvent servletRequestAttributeEvent) {
29         ServletContext application=servletRequestAttributeEvent.getServletContext();
30         //获取添加的属性名和属性值
31         String name=servletRequestAttributeEvent.getName();
32         Object value=servletRequestAttributeEvent.getValue();
33         System.out.println(application+"范围内添加了"+name+"值为"+value+"的属性");
34 
35     }
36 
37     @Override
38     public void attributeRemoved(ServletRequestAttributeEvent servletRequestAttributeEvent) {
39         ServletContext application=servletRequestAttributeEvent.getServletContext();
40         //获取添加的属性名和属性值
41         String name=servletRequestAttributeEvent.getName();
42         Object value=servletRequestAttributeEvent.getValue();
43         System.out.println(application+"范围内删除了"+name+"值为"+value+"的属性");
44     }
45 
46     @Override
47     public void attributeReplaced(ServletRequestAttributeEvent servletRequestAttributeEvent) {
48         ServletContext application=servletRequestAttributeEvent.getServletContext();
49         //获取添加的属性名和属性值
50         String name=servletRequestAttributeEvent.getName();
51         Object value=servletRequestAttributeEvent.getValue();
52         System.out.println(application+"范围内替换了"+name+"值为"+value+"的属性");
53     }
54 }

 

以上是关于JavaEE企业应用实战学习记录requestListener的主要内容,如果未能解决你的问题,请参考以下文章

JavaEE企业应用实战学习记录authorityFilter

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

JavaEE企业应用实战学习记录sessionListener

JavaEE企业应用实战学习记录struts国际化

JavaEE企业应用实战学习记录getConnListener

JavaEE企业应用实战学习记录struts2登录