This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Servlets and the fly likes Servlet's init() and destroy() method and constructors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Watch "Servlet New topic
Author

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

Shrikant Deshpande
Greenhorn

Joined: May 17, 2010
Posts: 15
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

Joined: Jan 10, 2002
Posts: 63195
    
  69

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.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Manish Singh
Ranch Hand

Joined: Jan 26, 2007
Posts: 160
You should not use the constructor init() method should be enough for your needs
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Servlet's init() and destroy() method and constructors
 
It's not a secret anymore!