监听器

servlet一共提供了三个类型的监听器类;

分别对request、session、application三个作用域对象进行监听。需要在web.xml文件中配置监听器;

request对象的监听器有两个类

ServletRequestListener 类 监听request对象创建、销毁。

      requestInitialized 监听request对象创建的方法;

      requestDestroyed 监听rquest对象销毁的方法。

ServletRequestAttributeListener类, 监听request对象属性值增删改;

      attributeAdded 监听request作用域对象新增一个属性值

      attributeRemoved 监听request作用域对象删除一个属性

      attributeReplaced 监听request作用域对象修改(替换)一个属性值

 

session对象的监听器有4个类

HttpSessionListener 类 监听session创建、销毁;

       sessionCreated 监听session创建的方法

       sessionDestroyed 监听sessioin销毁的方法

HttpSessionAttributeListener 类 监听session属性值增删改;

       attributeAdded 新增session属性值的方法

       attributeRemoved 删除session属性值的方法

       attributeReplaced 修改(替换)session属性值的方法

HttpSessionActivationListener session对象的迁移监听

HttpSessionBindingListener session对象的绑定监听(此监听器不需要web配置)

 

application对象的监听器有2个类

ServletContextListener 类 监听application对象创建、销毁;

    contextInitialized 创建application对象的方法

    contextDestroyed 销毁appclication对象的方法

ServletContextAttributeListener 类 监听application对象属性值增删改;

     attributeAdded 新增application属性值的方法

     attributeRemoved 删除application属性值的方法

     attributeReplaced 修改(替换)application属性值的方法

 

posted @ 2017-05-27 20:43  hdsfakjhf  阅读(147)  评论(0编辑  收藏  举报