File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Spring in Action this week in the Spring forum!
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: 61413
    
  67

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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet's init() and destroy() method and constructors