wood burning stoves 2.0*
The moose likes Servlets and the fly likes Shared temporary File  on server - deletion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Shared temporary File  on server - deletion" Watch "Shared temporary File  on server - deletion" New topic
Author

Shared temporary File on server - deletion

sonali ag
Greenhorn

Joined: Oct 08, 2009
Posts: 5
Hello all,

I want to delete a file after client closes browser or container/server get shutdown.

This file get created temporarily on server by servicing servlet and is shared among various listeners and servlet .
so i want to clean it up after responding to client.

Can anyone please suggest me the solution?

Also is it necessary to have this file within webapp context ?
or can it be outside my webapp folder? so that it can get deleted .

Thanks in advance.
Hasnain Javed Khan
Ranch Hand

Joined: Nov 23, 2007
Posts: 73
sonali ag wrote:
I want to delete a file after client closes browser or container/server get shutdown.


For container/server shutdown, you need to implement ServletContextListener Interface and write your cleanup logic in contextDestroyed() method.

As for the first part, there is no way to know if the client has closed the browser since there is no termination signal in HTTP protocol (guys correct me if I'm wrong). Sorry I have no ideas how to handle this case.

sonali ag wrote:
Also is it necessary to have this file within webapp context ?
or can it be outside my webapp folder? so that it can get deleted .


It can be inside or outside the webapp/context_root folder (not in webapp folder.Guys correct me if I'm wrong).

Hope that helped.
Kind Regards.
Hasnain.
 
Don't get me started about those stupid light bulbs.
 
subject: Shared temporary File on server - deletion