Skip to main content


Showing posts from July 5, 2016

Java code to be invoked when the server starts up

If you want to some java program to start by itself even you could not put in any type of start program or could not any utility. There is a smart way if you have one web server.

Creating a dynamic web project. Create a servlet out of your java program by extending it with HttpServlet.

On web.xml mention all servlet configuration like its name name, url pattern inside servlet mapping.

</servlet-mapping> we need to tell Servlet container to load your Servlet at startup.There are several ways to do this.  For Tomcat, set the load-on-startup element to 1 in the web.xml file.Every HttpServlet class needs to have an init() method. Normally it return nothing & takes no argument but it give you facility to put some code in init() method which will called when any HttpServlet is loaded.