一、ServletContext相关监听接口
1.ServletContextListener
1)职责:负责监听 Servlet Context 的生命周期 (该生命周期其实就对应着应用的生命周期,如ServletContext被创建和销毁)
2)接口方法 :
a. void contextInitialized(ServletContextEvent sce) 通知正在收听的对象,应用程序已经被加载和创建
b. void contextDestroyed(ServletContextEvent sce) 通知正在收听的对象,应用饮用程序被载出
c. ServletContextEvent中方法
ServletContext getServletContext() 取得sevletContext对象
2.ServletContextAttributeListenner
1)职责:用于监听web应用属性改变的时间,包含增删改属性
2)接口方法:
a. void attributeAdded(ServletContextAttributeEvent scab) 若有对象加入Application的范围,则通知正在收听的对象
b. void attributeRemoved(ServletContextAttributeEvent scab) 若有对象从Application范围删除,通知正在收听的对象
c. void attributeReplaced(ServletContextAttributeEvent scab) 若有对象从Application范围替换另一个对象,通知正在收听的对象
d.ServletContextAttributeEvent中的方法
String getName() 回传属性的名称
Object getValue() 回传属性的值
3.ServletContext说明
java虚拟机中,每一个web应用程序都对应一个ServletContext上下文。用于存放全局的信息,所有用户都可以使用。
扩展链接:http://blog.csdn.net/lvzhiyuan/article/details/4664624
二、HttpSession相关的监听接口
1.HttpSessionBindingListener 注意:HttpSessionBindingListener接口是唯一不需要再web.xml中设定的Listener
1) 职责:只要又对象加入session的范围(即调用HttpSession对象的setAttribute方法的时候)或移出范围(removeAtrribute方法 和 Session Time out的时候)时,通知接收对象。
2) 接口方法:
a. valueBound(HttpSessionBindingEvent event) 对象加入时通知接收对象
b. valueUnBound(HttpSessionBindingEvent event) 对象移出时通知接收对象
c. HttpSessionBindingEvent中的方法
HttpSession getSession () 获取更改后的session对象
String getName() 获取当操作属性的名称
Object getValue() 获取当操作属性的值
2.HttpSessionAttributeListener
1) 职责:监听HttpSession的属性操作
2) 接口方法解析:
a. attributeAdded ( HttpSessionBindingEvent se ) HttpSession添加一个属性值,通知接收对象
b. void attributeRemoved ( HttpSessionBindingEvent se ) HttpSession删除一个属性值,通知接收对象
c. attributeReplaced ( HttpSessionBindingEvent se ) HttpSession替换一个属性值,通知接收对象
3.HttpSessionListener
1) 职责:监听HttpSession的操作
2) 接口方法解析:
a. sessionCreated ( HttpSessionEvent se ). 创建一个Session时,通知接收对象
b. sessionDestroyed ( HttpSessionEvent se ) 销毁一个Session时,通知接收对象
c. HttpSessionEvent中方法
HttpSession getSession ()获取当前监听的session对象
4.HttpSessionActivationListener
1) 职责:主要用于同一个Session转移至不同的JVM的情形,感知自己何时随着HttpSession钝化/激活。
2) 接口方法解析:
a. sessionWillPassivate(HttpSessionEvent se) 通知Session即将被钝化
b. sessionDidActivate(HttpSessionEvent se) 通知Session即将被激活
5. HttpSession说明
web应用程序中,每个用户都有一个他独有的session与之对应,用于存储该用户的独有信息。
扩展链接:http://www.cnblogs.com/zhaoYuQing-java2015/p/4621384.html
三、ServletRequest监听接口
1.ServletRequestListener
1) 职责:监听请求,如:可用于统计网站中资源的访问次数
2) 接口方法解析:
a. requestDestroyed ( ServletRequestEvent sre ) 请求即将超出Web应用程序的范围(销毁)。
b.requestInitialized ( ServletRequestEvent sre ) 请求即将进入Web应用程序的范围(初始化)。
c.ServletRequestEvent中方法解析
ServletRequest getServletRequest () 返回变化中ServletRequest
ServletContext getServletContext () 返回该Web应用的ServletContext。
2. ServletRequestAttributeListener
1)监听ServletRequest的属性操作
2)接口方法解析
a. void attributeAdded(ServletRequestAttributeEvent srae)
b. void attributeRemoved(ServletRequestAttributeEvent srae)
c. void attributeReplaced(ServletRequestAttributeEvent srae)
d.ServletRequestAttributeEvent中的方法
String getName()
Object getValue()
3. HttpServletRequest 说明
用户对web应用程序的发起每一个请求,都对应一个HttpServletRequest,用于存储该请求的请求行、请求头和请求消息体等信息。
参考链接:http://blog.csdn.net/q547550831/article/details/50446180