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
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply 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: 56168
    
  13

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.

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About 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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Servlet's init() and destroy() method and constructors
 
Similar Threads
A Mock Question
Destroy Method in servlet constructor
can we write a program by implementing servlet?
init of servlets and jsp
jsp processing