wood burning stoves 2.0*
The moose likes Servlets and the fly likes Can i run a servlet on tomcat startup? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can i run a servlet on tomcat startup?" Watch "Can i run a servlet on tomcat startup?" New topic
Author

Can i run a servlet on tomcat startup?

Pradeep Daniel
Greenhorn

Joined: Oct 11, 2006
Posts: 12
I need to run a servlet code every time tomcat startup. Is it possible? Please let me know the procedure to achieve it and the configuration needed for it (ie, if any entry in the server.xml of tomcat is needed)
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
By adding <load-on-startup>1</load-on-startup> in your Servlet configuration, you can load your Servlet when Servlet starts.

<servlet>
<servlet-name></servlet-name>
<servlet-class></servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>


My blood is tested +ve for Java.
Chetan Parekh
Ranch Hand

Joined: Sep 16, 2004
Posts: 3636
But if your requirement is such that you want to execute / perform a specific task when your Server loaded, then better to use ContextListener.

Check this example for better understanding of ContextListener.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can i run a servlet on tomcat startup?
 
Similar Threads
Tomcat4.1.24 as a NT Service not working??
First steps with tomcat
loading a servlet on tomcat 5.5.1 startup
Is j2ee required for servlet?
HTTP Status 404 - Servlet springtest is not available