zoukankan      html  css  js  c++  java
  • Java 监听器

    监听器也叫Listener,是Servlet的监听器,它可以监听客户端的请求、服务端的操作等。通过监听器,可以自动激发一些操作,比如监听在线的用户的数量。

    :ServletContextListener监听ServletContext对象。

    新建一个web项目

    创建CountUtils和ListenerTest类并编写代码

    配置web.xml

    编写jsp页面

    运行代码并访问(两个人同时访问)

    常用的监听接口:

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

      ServletContextListener监听ServletContext对象。

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

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

    HttpSessionListener监听HttpSession的操作:

      当创建一个Session时,激发sessionCreated(HttpSessionEvent   se)方法;

      当销毁一个Session时,激发sessionDestroyed(HttpSessionEvent   se)方法。 

    HttpSessionAttributeListener监听HttpSession中的属性的操作:

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

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

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

  • 相关阅读:
    洛谷P1219 八皇后 我。。。。。。
    c++ STL map
    洛谷P1765 手机_NOI导刊2010普及(10) 关于cin和getline的一些区别 以及一些STL
    Restore the Permutation by Sorted Segments CodeForces
    Alternating Subsequence CodeForces
    cerr与cout
    (转)女生应该找一个玩ACM的男生
    (转)搞ACM的你伤不起
    c++多组数据输入
    不要62 HDU
  • 原文地址:https://www.cnblogs.com/guoqingyan/p/5686274.html
Copyright © 2011-2022 走看看