Cancelling a file download - "java.lang.IllegalStateException: getOutputStream() ..."
posted 7 years ago
I know a similar question has been asked before but I have not been able to solve my problem, I am unable to find any similar problems and solutions on any other forums.
I am developing a Struts 1.3 application which uses tiles, running on Tomcat 5.5. The download page uses a instance of Struts DownloadAction.
A user can successfully download a file. However the problem occurs if a user clicks to download a file, then from the 'Save/Cancel' dialog box clicks 'Cancel' at which point an exception is thrown, worryingly the console will continue to output exception stack trace for about 10 minutes before normal service is resumed!
To 'prove' where the issues arises I have run the software on both Linux and XP environments with the same outcome.
It starts to get interesting when I use a different browser, my target browser is IE 6, i get the same problem with IE 7 however using firefox 3.0.10 the error is not caused! I suspect the problem is down to the output stream being created for the file, perhaps firefox closes it properly when cancel is clicked but IE doesn't, in either case I would expect the code which manages to download on the server side to handle the error more elegantly.
Additionally files smaller than about 2Mb do not have the problem in IE.
I have knocked up a simple application which uses the download action but not running in the tiles framework, and this does not exhibit the problem, although it also does not include other elements of my full system, e.g. Acegi, various logging filters etc.
I would be grateful if anyone could offer some insight into what is causing this problem, or why the exception trace is so long if no actual fix is possible. if it is tiles (as has been suggested) to blame then we could look at alternatives to get around this problem.
(I keep getting an error trying to upload my stack trace in an attached file)