struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rahul Mohan <>
Subject Re: File Download with multiple files. Design question
Date Fri, 19 Nov 2010 10:01:03 GMT

In my project, we implemented a FileManager for storing, retrieving and 
cleaning up files. On upload, the filemanager creates a temp file on disk 
and stores the file-URL in a map correlated with the session id. We also 
implemented a SessionListener which calls FileManager.deleteFiles()  with 
the session-id as a parameter whenever a session is invalidated.  Deleting 
file after finish of streaming might not be a good idea, since it is very 
common to download the same file multiple times.

- Rahul

RogerV <>
19-11-2010 15:14
File Download with multiple files. Design question


I have a requirement to present the user with a list of files stored on 
server, and then download the files selected to the user. If the user
selects a single file - no problem. However if the user selects multiple
files, then, unless anyone knows different, all the files have to be sent 
the single input stream read by the stream result. Therefore I create a
temporary file with File.createTempFile() and use the ZipOutputStream to 
the files and then return an input stream over the temp file. This works
suprisingly well. However, the problem I've now got is, how to get rid of
the temp files I am creating on the server?

file.deleteOnExit() is no use because the server VM will (in theory) never
shutdown. Once the download is complete Struts automatically re-displays 
original selection screen and provided the user uses the applicatoin
supplied navigation to exit then I can delete the temp file, but if they
simply close the browser or use the browser back button to navigate away 
still left with the temp files sitting around. 

Creating the zipfile in memory is not an option as some of these can
potentially be huge if the user goes mad and selects everything in sight.

Is there someway of detecting/intercepting the fact that the Stream result
has completed before Struts gets on with deciding what .jsp to display 
so that I can safely clean up? Any other suggested approaches would be


View this message in context:

Sent from the Struts - User mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message