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 destroying the servlet  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "destroying the servlet  " Watch "destroying the servlet  " New topic
Author

destroying the servlet

Shreenivaas Reddy
Greenhorn

Joined: Jul 04, 2006
Posts: 7
how many ways we can destroy the servlet in our program?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

What do you mean by "destroy" the servelt?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42950
    
  72
Not sure what exactly you're trying to do, but a web application does not concern itself with the lifecycle of servlets - the servlet container does.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Though you don't destroy a servlet, it's the job of container.

But if you will call System.exit() or you will shutdown the server then container will destroy the all the servlets... Right??? :roll:
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12836
    
    5
If what you want is to prevent a servlet from responding to requests, have it throw a javax.servlet.UnavailableException - the container will then reject requests.
In the Tomcat servlet engine you can use the Manager interface to stop, start or reload an entire "web application" - which might be many servlets and jsp.
In case you are wondering, the destroy() method is part of the servlet life cycle controled by the container and should never be called by your program. It exists so you can clean up resources used by the servlet when the container is removing the instance for some reason.
Bill
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by rathi ji:
Though you don't destroy a servlet, it's the job of container.

But if you will call System.exit() or you will shutdown the server then container will destroy the all the servlets... Right??? :roll:


Yes, and blowing the server up with a stick of dynamite will also destroy the servlet.
Neither would be a reasonable approach.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42950
    
  72
Sure, restarting the container (or even just the web app) will unload the servlets. Calling System.exit will not work if the container is running with a security manager, though.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: destroying the servlet