码迷,mamicode.com
首页 > 其他好文 > 详细

监听器 (Listener)

时间:2015-01-10 12:27:33      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:

1. Listener是Servlet的监听器,它可以监听客户端的请求、服务端的操作等。通过监听器,可以自动激发一些操作,比如监听在线的用户的数量。当增加一个HttpSession时,

    就激发sessionCreated(HttpSessionEvent se)方法,这样就可以给在线人数加1

2. 常用的监听接口有以下几个

     1). ServletContextAttributeListener监听对ServletContext属性的操作,比如增加、删除、修改属性

     2). ServletContextListener监听ServletContext。当创建ServletContext时,激发contextInitialized(ServletContextEventsce)方法;当销毁ServletContext时,激发

           contextDestroyed(ServletContextEventsce)方法

     3). HttpSessionListener监听HttpSession的操作

          当创建一个Session时,激发session Created(HttpSessionEventse)方法;

          当销毁一个Session时,激发sessionDestroyed (HttpSessionEventse)方法

     4). HttpSessionAttributeListener监听HttpSession中的属性的操作。

           当在Session增加一个属性时,激发 attributeAdded(HttpSessionBindingEventse)方法;

           当在Session删除一个属性时,激发attributeRemoved(HttpSessionBindingEvent se)方法;

           当在Session属性被重新设置时,激发attributeReplaced(HttpSessionBindingEvent se)方法

3. 文档中的deployment descriptor指的是web.xml

4. Spring通过监听服务器启动时,去加载配置文件

5. 很多框架利用监听器,监听一些服务器中相关属性变化,然后对框架内部相关代码进行调用

监听器 (Listener)

标签:

原文地址:http://www.cnblogs.com/Jtianlin/p/4214653.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!