This content has been marked as final. Show 4 replies
Okay, yes you're right.
The excel piece of code is:
This reflects where the file will write out to....
+workbook = Workbook.createWorkbook(new File("C:\\file_output\\"+output));+
Then I have loads of code to set up the headings and what goes in each cell of the spreadsheet.
Then I have
then I have the download piece.
Immediately after that I have the code I originally listed.
Your file is now ready to be <A href="./file_output/<%=output%>"> downloaded </a>
It seems I need to have a IF statement or something to tell it Only delete when the application is closed....but I don't know how to do that.
Oh, I see. You are generating this file on the server, then sending a link to the client so that he or she can download the file.
And your problem is that you want to wait until the client downloads the file before you delete it. But think about it: you send the link to the client. The client may have gone for lunch and may not download it for an hour. The client may have changed his/her mind and is NEVER going to download it.
So, you can't have your code wait for the client to download the file. If you really want to persist in generating a file for the client to download, then your best bet is to not delete it in your code at all. Instead, have some process which runs periodically and deletes "download files" which are more than a couple of days old.
But a better bet is to not generate a file at all. Instead, generate the spreadsheet and return that as the response, instead of returning HTML with a link. Then there aren't any files cluttering up your server. Google for "file download servlet" and you should find examples of how to do that.