Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to configure Tomcat to load a servlet

 
Arunabh Dash
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Arunabh Dash
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64985
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for ur reply.


Pleae use real words.
 
Harpreet Hira
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic