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 regarding init() method 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 "regarding init() method" Watch "regarding init() method" New topic

regarding init() method

Chaitanya Vivek
Ranch Hand

Joined: May 17, 2006
Posts: 36
Its on Page#102 of HFSJ.

why is there an init()method? Why is not a constructor enough for initializing a servlet?

Exprts, pls let me know the answer.
John Lincoln
Ranch Hand

Joined: Feb 11, 2003
Posts: 192
Because init does more than just instantiating the servlet. It does all the pre-work like setting up database connection any specific configurations required for the servlet.


Chaitanya Vivek
Ranch Hand

Joined: May 17, 2006
Posts: 36
Also init() method gives the servlet access to the ServletConfig and ServletContext objects, which the servlet needs to get info abt the servlet config and the web app.

thanks for the reply!
I agree. Here's the link:
subject: regarding init() method
It's not a secret anymore!