• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

init() method on servlets

 
Leandro Sales
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the init method in a servlet is called? At the first request or when it is instantiated or it is instantiated when the first request is made?
 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When the init method in a servlet is called?

After Loding servlet class and executing default constructor
At the first request or when it is instantiated or it is instantiated when the first request is made?

Best time to Load a Servlet class is decided by your server depending on the server confugration.

I am not able to recollect it but there is some tag called
<load-on-startup> (may be something diff)

Cheers
-Praful
[ October 05, 2004: Message edited by: Praful Thakare ]
 
marco borsato
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
init is called only once when the servletcontext is initialised (basically when you start tomcat). <load-on-startup>1</load-on-startup> says this servlet has highest priority at loading. 2 and higher numbers are loaded after servlets with 1 are loaded. I am not sure whether this is guaranteed or just a guideline.
 
Leandro Sales
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I�m using Tomcat and if I put <load-on-startup>4</load-on-startup>, init() method is called when the context is initialized, if I don�t put, init() methos is called only whne the first request is made...
 
Sami Sayeed
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
init will be called after executing the default constructor of the servlet, and a servlet config object shall be passed to init method,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic