HttpSessionListener和HttpSessionAttributeListener

public interface [color=red]HttpSessionListener[/color]
extends java.util.EventListener
Implementations of this interface are notified of changes to the list of active sessions in a web application. To receive notification events, the implementation class must be configured in the deployment descriptor for the web application

void sessionCreated(HttpSessionEvent se)
Notification that a session was created.
void sessionDestroyed(HttpSessionEvent se)
Notification that a session is about to be invalidated.


HttpSessionAttributeListener监听
HttpSession中的属性的操作。当在Session增加一个属性时,激发attributeAdded(HttpSessionBindingEvent se) 方法;当在Session删除一个属性时,激发attributeRemoved(HttpSessionBindingEvent se)方法;当在Session属性被重新设置时,激发attributeReplaced(HttpSessionBindingEvent se) 方法。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Listener(监听器)是Java语言中的一种设计模式,在Java Web中也有广泛的应用。Listener主要用于监听Web应用中的事件,当事件发生时,会触发相应的Listener中的方法,从而实现一些自定义的功能。 Listener主要有以下几种类型: 1. ServletContextListener:监听ServletContext的创建和销毁事件; 2. ServletRequestListener:监听ServletRequest的创建和销毁事件; 3. HttpSessionListener:监听HttpSession的创建和销毁事件; 4. ServletContextAttributeListener:监听ServletContext中属性的添加、修改和删除事件; 5. ServletRequestAttributeListener:监听ServletRequest中属性的添加、修改和删除事件; 6. HttpSessionAttributeListener:监听HttpSession中属性的添加、修改和删除事件; 7. HttpSessionBindingListener:监听HttpSession中的对象绑定和解绑事件; 8. HttpSessionActivationListener:监听HttpSession的钝化和活化事件。 Listener的主要功能包括: 1. 监听Web应用中的事件,当事件发生时,触发相应的方法,从而实现一些自定义的功能,比如记录日志、维护在线用户列表等; 2. 在事件发生前或发生后对相关对象进行修改或处理,从而实现一些常见的功能,比如权限控制、字符编码转换、请求参数过滤等; 3. 在Web应用启动和关闭时执行一些初始化和清理工作,比如初始化数据库连接池、清理临时文件等。 总的来说,Listener是Java Web中的一种非常有用的组件,可以方便地监听Web应用中的事件,从而实现一些自定义的功能或常见的操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值