Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Constructor in Servlet

 
pulijala hari
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was going to mention this but forgot. Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic