permaculture playing cards*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes role of construcutors in servlets 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 "role of construcutors in servlets" Watch "role of construcutors in servlets" New topic
Author

role of construcutors in servlets

RAMA KRISHNA AALLA
Greenhorn

Joined: Aug 10, 2005
Posts: 29
What r the roles of a constructor inside a servlet ?
Why do we need constructors?
can we have OVERLOADED CONSTRUCTORS INSIDE A SERVLET?

Thx in advance..


Cheers
Rama Krishna Chowdary
Sergey Tyulkin
Ranch Hand

Joined: May 10, 2005
Posts: 87
There's no need to use a constructor in servlets, because:
1) Web container will create servlets using default constructor. So, you can't overload constructors
2) The web container's services may not be accessible during instantiation of the servlet, so you can't use the constructor for such tasks, as database connection creation, JNDI lookups and so on. Use init() method instead.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: role of construcutors in servlets