This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
mohit rastogi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to make a servlet to run at startup of the application
 
Mohamed Alatroush
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
IBM DB2 Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Minh Nam
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic