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)   方法。

  • 相关阅读:
    OO第三单元总结
    OO第二单元总结
    OO第一单元总结
    OO第四单元总结
    OO第三单元总结
    OO第二单元总结
    OO第一单元总结
    BUAA_OO_2020_Total_Summary
    BUAA_OO_2020_Unit3_Summary
    BUAA_OO_2020_Unit2_Summary
  • 原文地址:https://www.cnblogs.com/guoqingyan/p/5686274.html
Copyright © 2011-2022 走看看