Deleting files after session expired in Java web application

I have a java web application that generates and displays graphical images based on some custom settings.

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

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

The question is, how can I delete the generated file after the session expires? I don't want to get hung up on a lot of graphics, and I don't like the idea of ​​just emptying the folder with the generated graphics at midnight, since the user might be using my site at that time.

It is also possible that there are other means to achieve what I want. I am wondering what is the best fit for this kind of search from the server.

+2


a source to share


1 answer


Create a session listener HttpSessionListener and delete the file in



 public void sessionDestroyed(HttpSessionEvent se);

      

+4


a source







All Articles