天天看點

2、javaweb listener 對象的屬性變更--監聽

ServletContextAttributeListener, HttpSessionAttributeListener 和ServletRequestAttributeListener,這三個接口中都定義了三個方法來處理被監聽對象中的屬性的增加,删除和替換的事件,同一個事件在這三個接口中對應的方法名稱完全相同,隻是接受的參數類型不同。

attributeAdded 方法:

attributeRemoved 方法

attributeReplaced 方法

<listener>

<listener-class>listener.MyServletContextAttributeListener</listener-class>

</listener>

jsp測試;

 <%

//往application域對象中添加屬性

application.setAttribute("name", "nick");

//替換application域對象中name屬性的值

application.setAttribute("name", "gacl");

//移除application域對象中name屬性

application.removeAttribute("name");

%>

ServletContextListener監聽ServletContext域對象(application)中的屬性值的變化情況。

同理對其他兩個監聽進行測試。