aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes init() method on servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "init() method on servlets" Watch "init() method on servlets" New topic
Author

init() method on servlets

Leandro Sales
Greenhorn

Joined: Oct 03, 2004
Posts: 10
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?


Leandro Sales<br />SCJP 1.4<br />SoftSite Tecnologia
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 614
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 ]

All desirable things in life are either illegal, banned, expensive or married to someone else !!!
marco borsato
Ranch Hand

Joined: Aug 30, 2004
Posts: 55
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

Joined: Oct 03, 2004
Posts: 10
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

Joined: Oct 05, 2004
Posts: 39
Hi,
init will be called after executing the default constructor of the servlet, and a servlet config object shall be passed to init method,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: init() method on servlets