File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes how to make a servlet to run at startup of the application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "how to make a servlet to run at startup of the application" Watch "how to make a servlet to run at startup of the application" New topic
Author

how to make a servlet to run at startup of the application

mohit rastogi
Greenhorn

Joined: Jan 14, 2007
Posts: 7
how to make a servlet to run at startup of the application
Mohamed Alatroush
Greenhorn

Joined: Oct 05, 2011
Posts: 1
add this to the servlet definition at web.xml

<load-on-startup>1</load-on-startup>


for eg

<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>servlet.MyServlet</servlet-class>

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

olivier dutranoit
Ranch Hand

Joined: Aug 20, 2011
Posts: 81

Mohamed Alatroush wrote:add this to the servlet definition at web.xml

<load-on-startup>1</load-on-startup>


for eg

<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>servlet.MyServlet</servlet-class>

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



true, but take care of the "load-on-startup" parameter.
it can depend the kind of server you are deploying on.

sun servers and websphere CAN use different numbers.
i remember at the time that on the sun server it had to be "-1" or it didn't work.
Don't know about tomcat itself. also 1 i supose.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Why do you need to do this? If you are using a servlet to try and perform initialization for the web app, that's the wrong approach.

Rather, a context listener should be used.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Minh Nam
Ranch Hand

Joined: Sep 10, 2011
Posts: 57
mohit rastogi wrote:how to make a servlet to run at startup of the application

What do you mean by saying "make a servlet to run"?
Does it mean the one of the Servlet's HTTP methods (POST, GET) get called?


Advanced java topics
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: how to make a servlet to run at startup of the application