Listener 监听器



2014年9月8日 16:46:36



一、监听器概念
1、事件源:发生事件的对象。
2、监听器:是一个接口,监听事件源上要发生的动作
3、事件:事件对象一般是作为监听器方法的参数存在的,它封装了发生事件的对象

二、观察者设计模式


三、Servlet中提供的监听器(8个)

八个监听器分类:

1、监听ServletContext、HttpSession、ServletRequest对象的创建和销毁的监听器。
ServletContextListener:监听ServletContext对象的创建和销毁。
HttpSessionListener:监听HttpSession对象的创建和销毁。
创建:第一次调用request.getSession()时。
  销毁:1、主动调用invalidate()方法
2、超时
ServletRequestListener:监听ServletRequest对象的创建和销毁。

2、监听ServletContext、HttpSession、ServletRequest对象中域变化(新来的,替换的,删除的)的监听器。
ServletContextAttributeListener:
HttpSessionAttributeListener:
ServletRequestAttributeListener:


3、感知型监听器:谁实现了这些接口,谁就能感知自己被怎么着了。这种监听器不需要注册。
HttpSessionActivationListener:感知自己何时随着HttpSession对象钝化和活化
HttpSessionBindingListener:感知自己何时被HttpSession对象绑了(绑在域中)和解绑了。

编写步骤:
1、编写一个类实现某个监听器接口
2、在web.xml中注册监听器
<listener>
<listener-class>cn.itcast.listener.ServletContextDemoListener</listener-class>
</listener>

2014年9月8日 16:46:36



一、监听器概念
1、事件源:发生事件的对象。
2、监听器:是一个接口,监听事件源上要发生的动作
3、事件:事件对象一般是作为监听器方法的参数存在的,它封装了发生事件的对象

二、观察者设计模式


三、Servlet中提供的监听器(8个)

八个监听器分类:

1、监听ServletContext、HttpSession、ServletRequest对象的创建和销毁的监听器。
ServletContextListener:监听ServletContext对象的创建和销毁。
HttpSessionListener:监听HttpSession对象的创建和销毁。
创建:第一次调用request.getSession()时。
  销毁:1、主动调用invalidate()方法
2、超时
ServletRequestListener:监听ServletRequest对象的创建和销毁。

2、监听ServletContext、HttpSession、ServletRequest对象中域变化(新来的,替换的,删除的)的监听器。
ServletContextAttributeListener:
HttpSessionAttributeListener:
ServletRequestAttributeListener:


3、感知型监听器:谁实现了这些接口,谁就能感知自己被怎么着了。这种监听器不需要注册。
HttpSessionActivationListener:感知自己何时随着HttpSession对象钝化和活化
HttpSessionBindingListener:感知自己何时被HttpSession对象绑了(绑在域中)和解绑了。

编写步骤:
1、编写一个类实现某个监听器接口
2、在web.xml中注册监听器
<listener>
<listener-class>cn.itcast.listener.ServletContextDemoListener</listener-class>
</listener>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值