web监听器

1.Web监听器是Servlet规范中定义的一种特殊类,用于监听ServletContext、HttpSession、ServletRequest等域对象的创建与销毁事件


2.Web监听器的主要用途

1)统计在线人数和在线用户

2)系统启动时加载初始化信息

3)统计网站访问量

4)跟Spring结合

[*企业中应用]


3.Web监听器创建

1)实现Web接口类(ServletContextListener)

2)在web.xml中进行配置(listener)


4.监听器分类(按监听的事件划分)

1)监听域对象自身的创建和销毁的事件监听器

ServletContext——ServletContextListener

HttpSession——HttpSessionListener

ServletRequest——ServletRequestListener


contestDestroyed

ServletContext对象的创建和销毁?

创建:

销毁:


2)监听域对象中属性的增加和删除的事件监听器

ServletContext——ServletContextAttributeListener

HttpSession——HttpSessionAttributeListener

ServletRequest——ServletRequestAttributeListener

attributeAdded,attributeRemoved,attributeReplaced

3)监听绑定到HttpSession域中的某个对象的状态的事件监听器

HttpSession中对象的状态:绑定,解除绑定,钝化(持久化),活化

HttpSessionBindingListener valueBound(绑定),valueUnbound(解除绑定)

HttpSessionActivationListener sessionWillPassivate(钝化),sessinDidActivate(活化)

步骤:对象bean实现HttpSessionBindingListener ,HttpSessionActivationListener,Serializable接口并实现相应方法,将bean对象放到session attribute中。


5.Session的创建和销毁

创建:打开浏览器

销毁:

1)关闭服务器

2)关闭浏览器一段时间之后

3)不关闭浏览器,session超时

web.xml <session-config> <session-timeout> 以分钟为单位


6.Session钝化

正常情况下session处于服务器内存中,一些不常使用的session会被序列化,当需要使用时,再被反序列化到内存中

Session钝化机制由SessionManager管理

Tomcat两种session管理器——Persistentmanager,StandardManager

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值