JavaWeb——Listener

介绍

  Listener是监听域对象生命周期、域对象属性变更的对象

 

方法

HttpSessionBindingEvent sbe对象
  sbe.getName() 获取触发事件后session的属性名
  sbe.getSession() 获取session

 

 public void attributeAdded(HttpSessionBindingEvent sbe) {
      /* This method is called when an attribute 
         is added to a session.
      */
        String name = sbe.getName();
        System.out.println("sessoion的"+name+" 被添加属性"+sbe.getSession().getAttribute(name));
    }

    public void attributeRemoved(HttpSessionBindingEvent sbe) {
      /* This method is called when an attribute
         is removed from a session.
      */
        String name = sbe.getName();
        System.out.println("session的"+name+"被移除");
    }

    public void attributeReplaced(HttpSessionBindingEvent sbe) {
      /* This method is invoked when an attribute
         is replaced in a session.
      */
        String name = sbe.getName();
        System.out.println("session的"+name+"被替代为"+sbe.getSession().getAttribute(name));
    }

 

posted @ 2021-09-21 13:19  remix_alone  阅读(37)  评论(0)    收藏  举报