第1章 Listener监听器
1.1 Listener对象分类
Servlet的Listener监听器包括三种类型:
1、ServletContextListener 监听ServletContext对象
public void contextInitialized(ServletContextEvent event);
public void contextDestoryed(ServletContextEvent event);
2、HttpSessionListener 监听Session对象
public void sessionCreated(HttpSessionEvent event);
public void sessionDestoryed(HttpSessionEvent event);
1、 HttpRequestListener 监听Request对象
public void requestinitialized(ServletRequestEvent event);
public void requestDestoryed(ServletRequestEvent event);
Web.xml文件配置
<listener>
<listener-class>listener.MyListener</listener-class>
</listener>
1.2 Listener按属性分类
按照监听事件类型划分分为如下类型:
1、 用于监听域对象自身的创建和销毁的事件监听器。
2、 用于监听域对象的属性的增加和删除的事件监听器。
3、 用于监听绑定到HttpSession域中的某个对象的状态的事件监听器。
1.2.1 监听对象的属性事件监听器接口
1、 attributeAdd当被监听域对象中增加属性时会调用该系列监听器
public void attributeAdded(ServletContextAttributeEvent event);
public void attributeAdded(HttpSessionBindingEvent event);
public void attributeAdded(ServletRequestAttributeEvent event);
2、 attributeRemoved当被监听域对象中删除属性时会调用该系列监听器
public void attributeRemoved(ServletContextAttributeEvent event);
public void attributeRemoved(HttpSessionBindingEvent event);
public void attributeRemoved(ServletRequestAttributeEvent event);
3、 attributeReplaced当被监听域对象中属性变更时时会调用该系列监听器
public void attributeReplaced(ServletContextAttributeEvent event);
public void attributeReplaced(HttpSessionBindingEvent event);
public void attributeReplaced(ServletRequestAttributeEvent event);
注:使用属性监听器需要继承如下接口,实现以上方法
ServletContextAttributeListener,
HttpSessionAttributeListener,
ServletRequestAttributeListener
1.2.2 感知Session绑定的事件监听器
保存到Session域中的对象可以有多种状态:
1、 绑定到Session域中
2、 从Session域中解除绑定
3、 Session对象持久化到存储设备
4、 Session对象从一个存储设备中恢复
可以使用
HttpSessionBindingListener、HttpSessionActivationListener
两个监听接口实现JavaBean对象的绑定,从而了解JavaBean对象在Session域的状态。
HttpSessionBindingListener
public void valueBound(HttpSessionBindingEvent event);
public void valueUnbound(HttpSessionBindingEvent event);
HttpSessionActivationListener
public void sessionWillPassivate(HttpSessionEvent event);
注:当Session对象持久化到文件系统时,激活上面方法。
public void sessionDidActivate(HttpSessionEvent event);
注:当Session对象从文件系统恢复时,激活上面方法。
分享到:
相关推荐
listener监听器小例子
Listener监听器 JavaBean Servlet Jsp XML HTML JAVA WEB开发技术 Listener监听器 事件监听器用于对程序中发生的事件进行监听,在监听的过程中会涉及几个重要组成部分: 事件(Event) 事件源 事件处理器 事件监听器...
STRUTS:listener监听器
JAVALISTENER监听器教程及实例借鉴.pdf
java_listener监听器教程及实例.pdf
JavaWebServlet+JSP+EL表达式+JSTL标签库+Filter过滤器+Listener监听器
我们在编写JSP/Servle程序时,有相应的事件处理机制,在JSP/Servlet中是在web.xml中注册Listener,由Container在特定事件发生时呼叫特定的实现Listener的类。
监听器的分类 : 1 监听域对象自身的创建和销毁的事件监听器 2 监听域对象中的属性的增加和删除的事件监听器3 监听绑定到HttpSession域中的某个对象的
java消息推送技术中的监听器类,用于创建和监听通道数据
主要介绍了Spring ApplicationListener监听器用法详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
下面小编就为大家带来一篇基于Listener监听器生命周期(详解)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
Filter过滤器和Listener监听器详解 Filter过滤器 Filter的简介 对资源的访问进行过滤,相当于小区的保安,进去要检查,出去还要检查。 Filter的使用 编写一个类,继承并实现javax.servlet.Filter。 package ...
JavaWeb新版教程. jsp--什么是Listener监听器.avi
本文介绍了Listener以下几个方面的内容: · Listener的定义与作用 · Listener的分类与使用 ServletContext监听 Session监听 Request监听 · Listener的应用实例 利用HttpSessionListener统计...
很好的教学ppt是关于:Web页面的过滤与监听
监听器(Listener)的注册方法和 Servlet 一样,有两种方式:代码注册或者注解注册。接下来通过本文给大家介绍Spring Boot的listener(监听器)简单使用,需要的朋友可以参考下
Oracle数据库监听器(LISTENER)和本地服务名(Tnsname)配置.docx
Oracle 监听器 Listener资料.docx
关于监听器Listener和过滤器的小demo,自己学完这一节之后,做的一点点小练习。
主要给大家介绍了关于java监听器实现和原理的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用java具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧