wood burning stoves*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "regarding init() method" Watch "regarding init() method" New topic
Author

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.

HTH

thanks
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!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: regarding init() method
 
Similar Threads
difference b/w init() and init( config)
Why Init Method, why can't we use constructor instead?
Why Init() method
java.sql.SQLException: Closed Connection
Difference between init and servlet constructor