File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes When init() method is called? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "When init() method is called?" Watch "When init() method is called?" New topic

When init() method is called?

Veena Pointi
Ranch Hand

Joined: Jun 20, 2002
Posts: 442
When servlet is instantiated and init() method is called ?In book it is given before first client request,that means when we start the server?

"Continuous effort - not strength or intelligence - is the key to unlocking our potential."
*Winston Churchill
Martyn Clark
Ranch Hand

Joined: Apr 16, 2005
Posts: 108
Hi Veena
It maybe when the web app is loaded or when servlet is first called and it can not service any requests until after the init() method is complete.

Martyn...<br /> <br />SCJP 1.4 SCWCD 1.4
Veena Pointi
Ranch Hand

Joined: Jun 20, 2002
Posts: 442
Thanks.Yeah,figured out it is done either during container start up or first request.This is container specific.
Abhijeet Kadam

Joined: Sep 24, 2005
Posts: 24
init() is called either at web container start up or first request but there are some protocals which insure that it is called at startup
SCJP 1.4
Narendra Dhande
Ranch Hand

Joined: Dec 04, 2004
Posts: 951

If the <servlet> element has a <load-on-startup> then the servlet is initialized at the time of server startup/(re-)deployment of application. At this time the init() method is called. Other-wise prior to first request is received for this servlet.


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
Deepti Padiyar
Ranch Hand

Joined: Apr 27, 2006
Posts: 31
Even if <load-on-startup> is not specified in the DD, it depends on the web-container when it wnats to load the servlet class, either when the server is started, at startup , or when the first request comes in. My servlet's init() method is called whne the server starts up even when it does not have any <load-on-startup> associated with it.
[ July 12, 2006: Message edited by: Sumita Padiyar ]

Regards,<br />Deepti.
I agree. Here's the link:
subject: When init() method is called?
It's not a secret anymore!