Is there a means of executing code during the startup of Apache Tomcat 6.x to perform initialization routines, etc.?

后端 未结 2 539
感情败类
感情败类 2021-01-04 10:39

I want to initialize a global instance of a class before my Tomcat server completes startup and begins to offer my servlets. If this service somehow fails initialization, I

2条回答
  •  滥情空心
    2021-01-04 11:03

    Each web application has a ServletContext associated with it. The ServletContext object is created when the application is started and is destroyed when the application is shut down. A ServletContext has a global scope and is similar to a global variable in an application.

    http://www.javabeat.net/tips/178-servletcontextlistener-example.html

    complete explanation here

    http://onjava.com/pub/a/onjava/2001/04/12/listeners.html

提交回复
热议问题