2012-11-09 39 views
0

我在Apache Tomcat服務器上部署了web應用程序,並且在部署主Web應用程序後需要啓動另一個控制檯應用程序(套接字服務器)。此套接字服務器與主應用程序具有相同的WAR文件,並且可以訪問所有的Web應用程序的Bean和類。
我需要啓動後部署的web應用程序啓動tomcat(不是在打開應用程序或其他東西的索引頁後)
我該怎麼做?啓動tomcat後執行一些東西

回答

1

您需要實現ServletContextListner接口

public class MyServletContextListener implements ServletContextListener { 

    @Override 
    public void contextDestroyed(ServletContextEvent arg0) { 
    //Notification that the servlet context is about to be shut down. 
    } 

    @Override 
    public void contextInitialized(ServletContextEvent arg0) { 
    // do all the tasks that you need to perform just after the server starts 

    //Notification that the web application initialization process is starting 
    } 

} 

而在你的部署描述符中配置它web.xml

<listener> 
    <listener-class> 
     mypackage.MyServletContextListener 
    </listener-class> 
</listener> 
0

使用的ServletContextListener,你可以在web.xml

你會得到手柄,web應用程序啓動時,也當Web應用程序停止配置。

相關問題