Servlet监听器

①什么是Servlet监听器?

其主要功能就是监听Web的各种操作,当相关的操作促发后讲产生的时间,并对此事件进行处理。

监听器接口:

ServletContextListener接口用于监听Web应用程序启动和销毁的事件。
contextInitialized(ServletContextEventsce):通知正在接受的对象,应用程序已经被加载及初始化
contextDestroyed(ServletContextEventsce):通知正在接受的对象,应用程序已经被销毁 
ServletContextAttributeListener监听对ServletContext属性的操作,比如增加、删除、修改属性。

     当创建ServletContext时,激发contextInitialized (ServletContextEvent sce)方法;

当销毁ServletContext时,激发contextDestroyed(ServletContextEvent sce)方法。

HttpSessionBindingListener 接口有两个方法
voidvalueBound(HttpSessionBindingEvent event):当对象正在绑定到Session中,Servlet容器调用该方法来通知该对象
voidvalueUnbound(HttpSessionBindingEvent event):当从Session中删除对象时,Servlet容器调用该方法来通知该对象
HttpSessionAttributeListener 接口
监听HttpSession中的属性的操作
当在Session中增加一个属性时,激发 attributeAdded(HttpSessionBindingEventse)方法;
当在Session删除一个属性时,激发 attributeRemoved(HttpSessionBindingEventse)方法;
当在Session属性被重新设置时,激发 attributeReplaced(HttpSessionBindingEventse)方法。 

HttpSessionListener 接口

监听HttpSession对象的创建和销毁操作
当创建一个Session时,激发 sessionCreated(HttpSessionEvent se)方法
当销毁一个Session时,激发 sessionDestroyed(HttpSessionEvent se)方法

监听请求生命周期内事件

请求作用域范围内的生命周期事件用于管理整个request生命周期的状态和资源
ServletRequestListener接口
publicvoid requestDestroyed(ServletRequestEvent sre) :当请求被销毁时被处理。
publicvoid requestInitialized(ServletRequestEvent sre) :当请求被创建时被处理
ServletRequestAttributeListener接口
publicvoid attributeAdded(ServletRequestAttributeEvent arg0) :当在请求作用域中添加一个属性的时候调用该方法。
publicvoid attributeRemoved(ServletRequestAttributeEvent arg0) :当在请求作用域中删除一个属性时调用
publicvoid attributeReplaced(ServletRequestAttributeEvent arg0) :当在请求作用域中替换一个属性值的时候调用

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值