2012-11-09 5 views
0

웹 응용 프로그램을 Apache Tomcat 서버에 배포했으며 기본 웹 응용 프로그램을 배포 한 후 다른 콘솔 응용 프로그램 (소켓 서버)을 시작해야합니다. 이 소켓 서버는 기본 응용 프로그램과 동일한 WAR 파일에 있으며 모든 bean 및 클래스의 웹 응용 프로그램에 액세스 할 수 있습니다.
배포 된 웹 응용 프로그램을 사용하여 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을

당신은 핸들을 얻을 것이다, 웹 응용 프로그램을 시작하고 또한 웹 응용 프로그램 정지시에 구성 할 수 있습니다.

관련 문제