2009-12-07 38 views

回答

4

執行ServletContextListener並掛鉤contextDestroyed()

基本例如:

public class Config implements ServletContextListener { 

    public void contextInitialized(ServletContextEvent event) { 
     // Write code here which should be executed on webapp startup. 
    } 

    public void contextDestroyed(ServletContextEvent event) { 
     // Write code here which should be executed on webapp shutdown. 
    } 

} 

並將其註冊爲在web.xml一個<listener>

<listener> 
    <listener-class>com.example.Config</listener-class> 
</listener> 
1

一旦你到JAVA EE-6 +,註釋與@WebListener一類並實現對類的ServletContextListener得到關閉通知。無需處理web.xml。見here

相關問題