permaculture playing cards*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Method called during servlet initialization 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 "Method called during servlet initialization" Watch "Method called during servlet initialization" New topic
Author

Method called during servlet initialization

P. Jain
Greenhorn

Joined: Jan 03, 2008
Posts: 15
I am studying from 2 books i.e Head first Servlets and Jsp and SCWCD Kit by Hanumant Deshmukh.

My problem is that one book says that init(servletconfig) is called during initialization and other book says that init() method is called.

I just want to confirm which method is called?


SCJP 5.0<br />SCWCD 5.0<br />Preparing for SCDJWS
Shruthi Karthick
Ranch Hand

Joined: Mar 12, 2008
Posts: 45
Both the methods are called during servlet initialization only.

init(servletConfig) is called first.
init() is called from within init(servletConfig).
We can override init() for putting our own servlet initialization code.


Shruthi Karthick<br />SCJP - 93%<br />SCWCD - 89%
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41104
    
  45
The servlet container can't call init(), because it is not part of the Servlet interface. init() is a method of GenericServlet, so it doesn't necessarily exist (because you're free to create servlets that do not extend GenericServlet or its subclass HttpServlet).

This kind of information is generally -and specifically in this case- part of the javadocs.


Ping & DNS - my free Android networking tools app
P. Jain
Greenhorn

Joined: Jan 03, 2008
Posts: 15
Thanks for the reply. My doubt has been cleared.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Method called during servlet initialization
 
Similar Threads
labeling in this Applet..
Mechanism of init method to initialize servlet
servlet constructor & init method
question on filters from head first
labeling in this Applet..