2 Minutes To Code (β Version)

Apache Tomcat - 2 minute tutorial

How to configure servlets to run automatically on tomcat webserver start-up

If you need to do some sort of initialization (create db pool, http connection thread pool etc. ) before your servlet can receive http requests from clients, this can be done by using the element <load-on-startup> with a value of 1 as shown below in the deployment descriptor(web.xml).

When the webserver deploys your web-app (.war file), it will load all servlets that have a load-on-startup of 1.
<web-app>
   
   <servlet>
      <servlet-name>welcomePage</servlet-name>
      <servlet-class>com.techfundaes.servlets.Welcome</servlet-class>
      <load-on-startup>1</load-on-startup>
   </servlet>

   <servlet-mapping>
      <servlet-name>welcomePage</servlet-name>
      <url-pattern>/main/welcome.do</url-pattern>
   </servlet-mapping>

</web-app>