监听器

一、监听器:主要是用来监听特定对象的创建或销毁、属性的变化;是一个实现特定接口的普通java类。

二、servlet中哪些对象需要监听?

  request/session/servletContext

  分别对应,request监听器、session相关的监听器、servletContext监听器。

三、监听器的接口

(1)监听对象的创建/销毁

   Interface ServletRequestListener     监听request对象的创建或销毁

         Interface HttpSessionListener         监听session对象的创建或销毁

         Interface ServletContextListener     监听servletContext对象的创建或销毁

(2)监听对象属性的变化

     Interface ServletRequestAttributeListener  监听request对象属性变化: 添加、移除、修改

         Interface HttpSessionAttributeListener      监听session对象属性变化: 添加、移除、修改

   Interface ServletContextAttributeListener   监听servletContext对象属性变化

(3) session相关监听器

   Interface HttpSessionBindingListener             监听对象绑定到session上的事件    

        Interface HttpSessionActivationListener(了解)  监听session序列化及反序列化的事件

四、监听器的开发步骤

  (1)编写普通java类,实现相关的接口

  (2)配置(web.xml)

五、统计在线人数。实战

 

posted on 2017-01-23 20:49  hgfs瑞  阅读(97)  评论(0编辑  收藏  举报

导航