This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread 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


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: 42035
    
  64
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: 61310
    
  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.
 
GeeCON Prague 2014
 
subject: How to configure Tomcat to load a servlet