码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2016-10-06 00:22:37      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:

 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

标签:

原文地址:http://www.cnblogs.com/dream-to-pku/p/5933234.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!