views:

38

answers:

1

I have a java web application that generates and displays graphical pictures based upon some user parameters.

I used to store the graphics in the Session map, but that is generally not a good idea (you want to keep the session data as small as possible).

So instead, I only want to generate a file on the server and refer to it via an URL that I will store in the session map.

The question is: How can I remove the generated file after the session expires? I do not want to be stuck with a lot of graphics and I do not like the idea of just cleaning the folder with generated graphics at midnight as a user may be using my website at that time.

It could also be that there are other means to accomplish what I want. I'm interested what's the best practice for this kind of retrieval from the server.

+2  A: 

Create a session listener HttpSessionListener and remove the file in

 public void sessionDestroyed(HttpSessionEvent se);
ZZ Coder
Thanks, exactly what I needed. The implemented class must be added via a listener-class to web.xml
Roalt