更改對(duì)象的狀態(tài)稱為事件,事件基本上都是發(fā)生什么的東西。
在發(fā)生這些異常時(shí),我們也可以執(zhí)行一些重要任務(wù),例如計(jì)數(shù)總數(shù)和當(dāng)前登錄的用戶數(shù),在部署項(xiàng)目時(shí)創(chuàng)建數(shù)據(jù)庫(kù)的表,創(chuàng)建數(shù)據(jù)庫(kù)連接對(duì)象等。
javax.servlet和javax.servlet.http包中有許多Event類和Listener接口。
事件類
Servlet中的事件類如下:
ServletRequestEventServletContextEventServletRequestAttributeEventServletContextAttributeEventHttpSessionEventHttpSessionBindingEvent事件接口
Servlet中的事件接口如下:
ServletRequestListenerServletRequestAttributeListenerServletContextListenerServletContextAttributeListenerHttpSessionListenerHttpSessionAttributeListenerHttpSessionBindingListenerHttpSessionActivationListener有關(guān)Servlet事件和監(jiān)聽(tīng)器的介紹和應(yīng)用示例文章
ServletContextEvent和ServletContextListener的簡(jiǎn)單例子。HttpSessionEvent和HttpSessionListener的簡(jiǎn)單例子。ServletRequestEvent 和 ServletRequestListener的簡(jiǎn)單例子。ServletContextAttributeEvent 和 ServletContextAttributeListener的簡(jiǎn)單例子。HttpSessionBindingEvent 和 HttpSessionAttributeListener的簡(jiǎn)單例子。ServletRequestAttributeEvent 和 ServletRequestAttributeEvent的簡(jiǎn)單例子。