File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes execute a servlet  when tomcat starts up Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "execute a servlet  when tomcat starts up" Watch "execute a servlet  when tomcat starts up" New topic
Author

execute a servlet when tomcat starts up

Dave Bosky
Ranch Hand

Joined: Dec 16, 2003
Posts: 72
Is it possible to execute a servlet when Tomcat starts up?
I'm trying to do some connection pooling with datasource connections.
When Tomcat starts up I want to create a single connection instance and initialize some settings.

Thanks,
Dave
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

The best thing to do in those cases is use a context listener. Any class that implements javax.servlet.ServletContextListener will have to implement two methods, one of which is contextInitialized. In there, would be the best place to do your setup.

If you still want a servlet, then you can configure the servlet to 'load-on-startup' in web.xml.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: execute a servlet when tomcat starts up
 
Similar Threads
tomcat question
ServletContextListener Doubt??
Strange Problem : Redirect to other Servlet using dispatch
Timer starts twice when it should start only once
Timer starts twice when it should start only once