Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet's init() and destroy() method and constructors

 
Shrikant Deshpande
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who calls Servlet's init() and destroy() method?

How and when it gets called? Can we override destroy() method?

Can we have constructor inside servlet class which extends from HttpServlet or GenericServlet?




 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shrikant Deshpande wrote:Who calls Servlet's init() and destroy() method?
The container. (E.g. Tomcat, Weblogic, and so on)

How and when it gets called?
They get called just like any other method. Whne they get called is covered in the Servlet Spec -- when the servlet isplaced into service, and when it is removed from service.

Can we override destroy() method?
Yes, if you have something meaningful to do when the servlet is taken out of service.

Can we have constructor inside servlet class which extends from HttpServlet or GenericServlet?
Yes, but it's not a customary or useful thing to do.
 
Manish Singh
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not use the constructor init() method should be enough for your needs
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic