//使用ServletContextListener監(jiān)聽(tīng)器在Servlet API中有一個(gè)ServletContextListener接口,它能夠監(jiān)聽(tīng)ServletContext對(duì)象的生命周期,實(shí)際上就是監(jiān)聽(tīng)Web應(yīng)用的生命周期當(dāng)Servlet容器啟動(dòng)或終止時(shí),會(huì)觸發(fā)ServletContextEvent事件,該事件由ServletListener來(lái)處理,在ServletContextListener接口中定義了處理ServletContextEvent事件的兩個(gè)方法contextInitialized(ServletContextEvent sce):當(dāng)Servlet容器啟動(dòng)Web應(yīng)用時(shí)調(diào)用該方法,在調(diào)用該方法之后容器再對(duì)Filter初始化,并且對(duì)那些再Web應(yīng)用啟動(dòng)時(shí)就需要被初始化的Servlet初始化contextDestroyed(ServletContextEvent sce):當(dāng)Serlvet容器終止Web應(yīng)用時(shí)調(diào)用該方法,在調(diào)用該方法之前容器會(huì)銷(xiāo)毀所有的Serlvet和Filter過(guò)濾器
版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載。
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注