開發者學堂課程【Servlet入門:監聽器之 HttpSessionBindingListener】學習筆記,與課程緊密聯系,讓使用者快速學習知識。
課程位址:
https://developer.aliyun.com/learning/course/38/detail/889監聽器之 HttpSessionBindingListener
内容介紹
一、ServletContext
二、HttpSession
三、ServleRequest
四、六大監聽器
五、感覺監聽(都與 HttpSession 相關)
一、ServletContext:
屬性監聽:
ServletContextAttributeListener,它有三個方法,一個在添加屬性時調用,一個在替換屬性時調用,最後一個是在移除屬性時調用。
void attributeAdded(SerletcontextAttributeEvent event):添加屬性時;
void attributeReplaced(SevletContextAttributeEvent event):替換屬性時;
void attributeRemoved(ServletContextAttributeEvent event):移除屬性;
二、HttpSession:
HttpSessioniAttributeListener,它有三個方法,一個在添加屬性時調用,一個在替換屬性時調用,最後一個是在移除屬性時調用;
void attributeAdded(HttpSessionBindingExentevent):添加屬性時;
void attributeReplaced(HttpSessione.indingEvent Event):替換屬性時;
void attributeRemoved(HttpSessionBindingEvent Event):移除屬性時;
三、ServleRequest:
ServletRequestAttributeListener,它有三個方法,一個在添加屬性時調用,一個在替換屬性時調用,最後一個是在移除屬性時調用。
void attributeAdded(ServletRequestAttributeEvent srae):添加屬性時;
vvoid attributeReplaced(ServletRequestAttributeEvent srae):替換屬性時;
void attributeRemoved(ServletRequestAttributeEvent srae):移除屬性時;
四、六大監聽器:
SerxletContextExent: serxletContext getSerxletContext();
HttpSessionExent : HttpSession getSession();
SerMletReguest :
ServletContext getSerxletContext();
ServletRegues getSerxletReguest();
SerletContextAttributeEvent :
ServletConext.getServletContext();
String getName():擷取屬性名
Object getvalue():擷取屬性值
HttpSessionBindingEvent:略
ServletRequestAttributeEvent : 略
五、感覺監聽(都與HttpSession相關)
它用來添加到JavaBean上,而不是添加到三大域上!
這兩個監聽器都不需要在web.xml中注冊!
特點:
HittpSessionBindingListener:
添加到 javabea n上,javabean 就知道自己是否添加到 session 中了。