Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

role of construcutors in servlets

 
RAMA KRISHNA AALLA
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic