监听器

监听器

Jsp 2.0中,一共提供了8个监听器,详细列表如下:

 

监听器名称

作用

ServletContextListener

负责监听服务器的启动和停止,需要重写contextInitialized(服务器的启动)contextDestroyed()方法。

ServletContextAttributeListener

负责监听ServletContext属性的添加、删除和替换。需要重写attributeAdded(添加)attributeRemoved(删除)attributeReplaced(替换)方法。

HttpSessionListener

监听会话的创建和销毁。需要重写sessionCreated(创建)sessionDestroyed(销毁)方法。

HttpSessionAttributeListener

监听Session属性的添加、删除和替换。需要重写attributeAdded(添加)attributeRemoved(删除)attributeReplaced(替换)方法。

HttpSessionBindingListener

这个监听器和其他的监听器有所不同。它要完成的功能是这样的:我们可以让一个类实现HttpSessionBindingListener接口,当我们将一个实现HttpSessionBindingListener接口的对象加入到Session中的时候,就会触发这个对象的valueBound方法,当我们从Session中删除这个对象的时候,就会触发这个对象的valueUnbound方法。这是一个不需要在web.xml中设定的监听器。

HttpSessionActivationListener

这个监听器也是和HttpSessionBindingListener一样。当一个类实现HttpSessionActivationListener之后,如果将该对象加入到Session中,那么当Session钝化和激活的时候,它可以得到通知。当同一个Session在不同的JVM之间移动的时候,可以实现Session转台跟踪。需要重写sessionWillPassivatesessionDidActivate方法。Objects that are bound to a session may listen to container events notifying them that sessions will be passivated and that session will be activated. A container that migrates session between VMs or persists sessions is required to notify all attributes bound to sessions implementing HttpSessionActivationListener

ServletRequestListener

这个是在Jsp 2.0中新添加的监听器。监听请求的产生和消灭。需要重写requestInitialized方法和requestDestroyed方法。通过这个listener主要是要获取request对象,从而可以得到一些request的信息。

ServletRequestActtributeListener

这个监听器也是在Jsp 2.0中定义的。它是用来监听request范围内的变量的添加、修改和删除。需要重写attributeAddedattributeReplacedattributeRemoved方法。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值