Servlet---Listener

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package com.an.tomcatservlet;
 
import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletRequest;
import javax.servlet.ServletRequestAttributeEvent;
import javax.servlet.ServletRequestAttributeListener;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpSessionActivationListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
 
/**
 * @author apy
 * @description
 * @date 2021/10/21 17:29
 */
public class MyListener implements ServletRequestListener
        ,ServletRequestAttributeListener
        ,ServletContextListener
        ,ServletContextAttributeListener
        ,HttpSessionListener
        ,HttpSessionBindingListener
        ,HttpSessionActivationListener
        ,HttpSessionAttributeListener{
 
    public void requestInitialized(ServletRequestEvent sre) {
        ServletRequest servletRequest = sre.getServletRequest();
        // do something...
    }
 
    public void requestDestroyed(ServletRequestEvent sre) {
 
    }
 
    public void attributeAdded(ServletRequestAttributeEvent srae) {
 
    }
 
    public void attributeRemoved(ServletRequestAttributeEvent srae) {
 
    }
 
    public void attributeReplaced(ServletRequestAttributeEvent srae) {
 
    }
 
    public void contextInitialized(ServletContextEvent sce) {
 
    }
 
    public void contextDestroyed(ServletContextEvent sce) {
 
    }
 
    public void attributeAdded(ServletContextAttributeEvent event) {
 
    }
 
    public void attributeRemoved(ServletContextAttributeEvent event) {
 
    }
 
    public void attributeReplaced(ServletContextAttributeEvent event) {
 
    }
 
    public void sessionCreated(HttpSessionEvent se) {
 
    }
 
    public void sessionDestroyed(HttpSessionEvent se) {
 
    }
 
    public void valueBound(HttpSessionBindingEvent event) {
 
    }
 
    public void valueUnbound(HttpSessionBindingEvent event) {
 
    }
 
    /**
     * 【servlet Listener】
     *      why?
     *          解决 共享对象 内容发生变化 时, 在发生前、发生后 做处理;
     *
     *          Servlet2.3 提供了 对 ServletContext、HttpSession对象的变化的 监听器;
     *          Servlet2.4 增加了 对 ServletRequest对象的变化的 监听器;
     *
     *      what?
     *          ServletContext监听器:监听 ServletContext对象,可以 使 web应用 得知 web组件的 加载、卸载情况等;
     *              ServletContextListener
     *              ServletContextAttributeListener
     *
     *              ServletContextEvent
     *              ServletContextAttributeEvent
     *
     *          HttpSession监听器:监听 HttpSession对象变化,可以 使 web应用 了解 会话期间的状态 并 做出响应;
     *              HttpSessionListener
     *              HttpSessionActivationListener  实现数据 内存->磁盘,磁盘->内存;
     *
     *              HttpSessionEvent
     *
     *
     *              HttpSessionAttributeListener
     *              HttpSessionBindingListener
     *
     *              HttpSessionBindingEvent
     *
     *
     *          ServletRequest监听器:监听 ServletRequest对象变化,可以 使 web应用 控制web请求的生命周期;
     *              ServletRequestListener
     *              ServletRequestAttributeListener
     *
     *              ServletRequestEvent
     *              ServletRequestAttributeEvent
     *
     *      How?
     *          创建普通Java类,实现 对应的Listener,重写相应的方法;
     *          在web.xml中配置相应的 Listener;
     */
}

  

posted on   anpeiyong  阅读(16)  评论(0编辑  收藏  举报

编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示