ServletContextListener接口用法
生活随笔
收集整理的這篇文章主要介紹了
ServletContextListener接口用法
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
ServletContextListener接口用于tomcat啟動(dòng)時(shí)自動(dòng)加載函數(shù),方法如下:
一、需加載的類必須實(shí)現(xiàn)ServletContextListener接口。
二、該接口中有兩個(gè)方法必須實(shí)現(xiàn):
1、contextInitialized(ServletContextEvent sce)該方法為服務(wù)器起動(dòng)時(shí)加載內(nèi)容。
2、contextDestroyed(ServletContextEvent sce)該方法為服務(wù)器關(guān)閉時(shí)加載的內(nèi)容。
三、如:
四、web.xml配置listener標(biāo)簽
<listener><listener-class>ReadContext</listener-class> </listener>五、如果contextDestroyed不執(zhí)行多是因?yàn)閠omcat沒(méi)有正常關(guān)閉或是沒(méi)有實(shí)現(xiàn)ServletContextListener接口。在MyEclipse關(guān)閉tomcat的正確方法是:點(diǎn)擊右鍵點(diǎn)關(guān)閉
總結(jié)
以上是生活随笔為你收集整理的ServletContextListener接口用法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: linux搭建gitlab
- 下一篇: 大话架构”阿里架构师的笔记——多研究些架