This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
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