aspose file tools*
The moose likes Servlets and the fly likes Constructor in Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Constructor in Servlet" Watch "Constructor in Servlet" New topic
Author

Constructor in Servlet

pulijala hari
Ranch Hand

Joined: May 14, 2005
Posts: 70
Hi All,

Can we write our own constructor in servlet?

Although this might be basic , but i do not know whether we can write our own constructor in servlet and if we can write down that , what can be its uses and disadvantes?

regards,
hari
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Yes, we can write constructor for servlet. It will be called before init() method.
[ October 10, 2005: Message edited by: rathi ji ]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

No, you should not create your own constructor. While you're free to create your own constructor, if it is not the no-arg constructor it will never be called by the container.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Whatever you might want to write in constructor, you can write in init() method, in addition you have ServletConfig and ServletContext in init() method.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I was going to mention this but forgot. Thanks
 
Consider Paul's rocket mass heater.
 
subject: Constructor in Servlet