HttpSessionBindingListener和HttpSessionAttributeListener区别 - gengkunpeng的专栏 - 博客频道 - CSDN.NET
2014-07-30 14:51
711 查看
分享到
一键分享
QQ空间
新浪微博
百度云收藏
人人网
腾讯微博
百度相册
开心网
腾讯朋友
百度贴吧
豆瓣网
搜狐微博
百度新首页
QQ好友
和讯微博
更多...
百度分享
HttpSessionBindingListener和HttpSessionAttributeListener区别
2010-12-04 22:04 637人阅读 评论(0) 收藏 举报
sessionobjectuserclass
HttpSessionBindingListener和HttpSessionAttributeListener是两个经常让初学者弄混的监听器,其实它们有很大的区别。这2个监听器在文章中简称为BindingListener和AttributeListener.
1.BindingListener有2个方法,valueBound(HttpSessinBindingEvent)和valueUnbount(HttpSessionBindingEvent)。实现BindingListener接口的对象被绑 定到session时触发valueBound事件,解除绑定时触发valueUnbound事件。举例来说:
[c-sharp] view plaincopyprint?
public class UserObject implements HttpSessionBindingListener{
public void valueBound(HttpSessionBindingEvent event){
System.out.println("触发绑定事件!");
}
public void valueUnbound(HttpSessionBindingEvent event){
System.out.println("解除和session的绑定");
}
OtherObject other = new OtherObject();
当有对象添加到session中时,session.setAttribute("object",other)触发attributeAdded事件,
当该对象从session移除时,session.removeAttribute("object")触发attriubteRemoved事件,
当该属性的值发生变化时, session.replaceAttribute("object",another)触发attributeRepalced事件。
注意:只要有对象保存到session中或从session中移除或改变属性的值都会触发相应事件,不论该对象是否实现了AttributeListener。
总结:1.只有实现了HttpSessionBindingListener的类,在和session绑定、解除绑定时触发其事件。
2.实现了HttpSessionAttributeListener后,任何对象(不论其是否实现了AttributeListener)在变化时均触发对应的事件。
更多 0
一键分享
QQ空间
新浪微博
百度云收藏
人人网
腾讯微博
百度相册
开心网
腾讯朋友
百度贴吧
豆瓣网
搜狐微博
百度新首页
QQ好友
和讯微博
更多...
百度分享
HttpSessionBindingListener和HttpSessionAttributeListener区别
2010-12-04 22:04 637人阅读 评论(0) 收藏 举报
sessionobjectuserclass
HttpSessionBindingListener和HttpSessionAttributeListener是两个经常让初学者弄混的监听器,其实它们有很大的区别。这2个监听器在文章中简称为BindingListener和AttributeListener.
1.BindingListener有2个方法,valueBound(HttpSessinBindingEvent)和valueUnbount(HttpSessionBindingEvent)。实现BindingListener接口的对象被绑 定到session时触发valueBound事件,解除绑定时触发valueUnbound事件。举例来说:
[c-sharp] view plaincopyprint?
public class UserObject implements HttpSessionBindingListener{
public void valueBound(HttpSessionBindingEvent event){
System.out.println("触发绑定事件!");
}
public void valueUnbound(HttpSessionBindingEvent event){
System.out.println("解除和session的绑定");
}
[java] view plaincopyprint? MyListener implements HttpSessionAttributeListener{ attributeAdded(HttpSessionBindingEvenet event){ System.out.println("有对象加入session中"); } attributeRemoved(HttpSessionBindingEvent event){ System.out.println("有对象从session中移除"); } attributeReplaced(HttpSessionBindingEvent event){ System.out.println("属性值改变"); } } MyListener implements HttpSessionAttributeListener{ attributeAdded(HttpSessionBindingEvenet event){ System.out.println("有对象加入session中"); } attributeRemoved(HttpSessionBindingEvent event){ System.out.println("有对象从session中移除"); } attributeReplaced(HttpSessionBindingEvent event){ System.out.println("属性值改变"); } }
OtherObject other = new OtherObject();
当有对象添加到session中时,session.setAttribute("object",other)触发attributeAdded事件,
当该对象从session移除时,session.removeAttribute("object")触发attriubteRemoved事件,
当该属性的值发生变化时, session.replaceAttribute("object",another)触发attributeRepalced事件。
注意:只要有对象保存到session中或从session中移除或改变属性的值都会触发相应事件,不论该对象是否实现了AttributeListener。
总结:1.只有实现了HttpSessionBindingListener的类,在和session绑定、解除绑定时触发其事件。
2.实现了HttpSessionAttributeListener后,任何对象(不论其是否实现了AttributeListener)在变化时均触发对应的事件。
更多 0
相关文章推荐
- HttpSessionBindingListener和HttpSessionAttributeListener区别
- JS 动态修改 input 的 type 属性 - teresa502的专栏 - 博客频道 - CSDN.NET http://blog.csdn.net/teresa502/article/details/6546361
- csdn如何转载别人的文章 - jiangping_zhu的专栏 - 博客频道 - CSDN.NET http://blog.csdn.net/jiangping_zhu/article/detail
- C# UI常用操作 - Mars的专栏 - 博客频道 - CSDN.NET http://blog.csdn.net/shuyizhi/article/details/6830405
- jsp中<%%> 与<%!%> , <%%>与<%=%>的区别是什么? - u013305082的专栏 - 博客频道 - CSDN.NET
- PrintStream: - shichunle的专栏 - 博客频道 - CSDN.NET http://blog.csdn.net/shichunle/article/details/6754930
- Linux .o a .so .la .lo的区别及libtool相关介绍 - atoday20090810的专栏 - 博客频道 - CSDN.NET
- 理解和正确使用Java中的断言(assert) - Leichelle的专栏 - 博客频道 - CSDN.NET http://blog.csdn.net/leichelle/article/deta
- HttpSessionListener 、HttpSessionAttributeListener以及HttpSessionBindingListener 的区别
- <init>与<clinit>的区别 - 挨踢大杂烩 - 博客频道 - CSDN.NET http://blog.csdn.net/jamse19860909/article/details/7210
- Unity Mecanim在大型mmo中的应用 - langresser的专栏 - 博客频道 - CSDN.NET http://blog.csdn.net/langresser_king/artic
- HTTP Range说明 - lenoval的专栏 - 博客频道 - CSDN.NET
- tomcat里设置session过期时间 - moonlit1228的专栏 - 博客频道 - CSDN.NET
- java.ByteArrayInputStream与ByteArrayOutputStream再次理解 - CodeAnt的专栏 - 博客频道 - CSDN.NET http://blog.csdn.
- Ubuntu安装psycopg2小记 - Wally Yu的专栏 - 博客频道 - CSDN.NET
- GTK、GDK、GLIB三者的关系 - 阿堂的专栏 - 博客频道 - CSDN.NET
- HttpSessionBindingListener和HttpSessionListener之间的最大区别
- Glib学习笔记(4) - Innost的专栏 - 博客频道 - CSDN.NET
- HttpSessionListener 和HttpSessionBindingListener的区别(单点登陆时有用)
- java.lang.IllegalArgumentException: argument type mismatch解决方法 - shinn613的专栏 - 博客频道 - CSDN.NET