This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Constructor in Servlet
 
Similar Threads
Question for SCWCD.
Servlet Constructor
Can we write our own ActionServlet?
writing own constructor for servlet
init() method