• JAVAWEB监听器(二)


    监听域对象中属性的变更的监听器

      域对象中属性的变更的事件监听器就是用来监听 ServletContext, HttpSession, HttpServletRequest 这三个对象中的属性变更信息事件的监听器。
      这三个监听器接口分别是ServletContextAttributeListener, HttpSessionAttributeListener 和ServletRequestAttributeListener,这三个接口中都定义了三个方法来处理被监听对象中的属性的增加,删除和替换的事件,同一个事件在这三个接口中对应的方法名称完全相同,只是接受的参数类型不同。

    1、attributeAdded 方法

      当向被监听对象中增加一个属性时,web容器就调用事件监听器的attributeAdded方法进行响应,这个方法接收一个事件类型的参数,监听器可以通过这个参数来获得正在增加属性的域对象和被保存到域中的属性对象
      各个域属性监听器中的完整语法定义为:

    1 public void attributeAdded(ServletContextAttributeEvent scae)
    2 public void attributeReplaced(HttpSessionBindingEvent  hsbe)
    3 public void attributeRmoved(ServletRequestAttributeEvent srae)

    2、attributeRemoved 方法

      当删除被监听对象中的一个属性时,web容器调用事件监听器的attributeRemoved方法进行响应
      各个域属性监听器中的完整语法定义为:

    1 public void attributeRemoved(ServletContextAttributeEvent scae)
    2 public void attributeRemoved (HttpSessionBindingEvent  hsbe)
    3 public void attributeRemoved (ServletRequestAttributeEvent srae)

    3、attributeReplaced 方法

      当监听器的域对象中的某个属性被替换时,web容器调用事件监听器的attributeReplaced方法进行响应
      各个域属性监听器中的完整语法定义为:

    1 public void attributeReplaced(ServletContextAttributeEvent scae)
    2 public void attributeReplaced (HttpSessionBindingEvent  hsbe)
    3 public void attributeReplaced (ServletRequestAttributeEvent srae)
  • 相关阅读:
    【转】Android实战技巧:ViewStub的应用
    3.11 返回数据到前一个Activity
    在用android日志的时候老是弹出一个窗口,内容为:"Copy" did not complete normally. Please see the log 和 什么函数,能达到和android手机上按“返回”键一样的效果?
    Windows下的Android模拟器设置内存大小
    AlertDialog.Builder对话框类的用法(二)
    android版计算器
    【转】Android中字符串的拆分split
    readelf
    6200 uboot 测试版分析(二)
    cpp
  • 原文地址:https://www.cnblogs.com/future-zmy/p/6221014.html
Copyright © 2020-2023  润新知