• 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.
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!