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 Method called during servlet initialization 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 "Method called during servlet initialization" Watch "Method called during servlet initialization" New topic

Method called during servlet initialization

P. Jain

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

Joined: Mar 22, 2005
Posts: 42965
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.
P. Jain

Joined: Jan 03, 2008
Posts: 15
Thanks for the reply. My doubt has been cleared.
I agree. Here's the link:
subject: Method called during servlet initialization
jQuery in Action, 3rd edition