This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Servlets and the fly likes How to configure Tomcat to load a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to configure Tomcat to load a servlet " Watch "How to configure Tomcat to load a servlet " New topic
Author

How to configure Tomcat to load a servlet

Arunabh Dash
Greenhorn

Joined: Apr 05, 2006
Posts: 20
hi,
i m using Tomcat. Can any one tell me or sent me some url where i can get some information to configure Tomcat so that it will lode a specified servlet when it is started .
Need help desperately....
With regards
Arunabh
Ed Ward
Ranch Hand

Joined: Jan 30, 2006
Posts: 147
I didn't think this functionality was vendor specific.
I usually just use the <load-on-startup> subelement of <servlet>
As in:

<servlet>
...servlet stuff
<load-on-startup>5</load-on-startup>
</servlet>

The value you pass being the load priority.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
The Servlet API 2.3 introduced lifecycle events, which are a better solution to this (specifically, contextInitialized and contextDestroyed). Using a servlet purely for application initialization is kind of a hack.


Ping & DNS - my free Android networking tools app
Arunabh Dash
Greenhorn

Joined: Apr 05, 2006
Posts: 20
thank you for ur reply.
Where i have to set it. In the web.xml or some where in the servlet.
With regards
Arunabh
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

thank you for ur reply.


Pleae use real words.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Harpreet Hira
Ranch Hand

Joined: Sep 27, 2001
Posts: 72
In web.xml within the servlet tag put <load-on-startup> tag with a numeric value specifying the order in which the servlet should be loaded.

Example -
<servlet id="Servlet_26">
<servlet-name>NbaStartupServlet</servlet-name>
<servlet-class>com.mine.StartupServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

If you have more than one servlets to load on startup, you can use int value 2,3,... to specify the order in which the servlets should load at startup.
 
Don't get me started about those stupid light bulbs.
 
subject: How to configure Tomcat to load a servlet