This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Canceling file download??  RSS feed

Milan Tomc
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

When downloading files I get this well known "open/save/cancel window" to decide what to do.
Everything works fine. Or should I say, wordked fine, until I tried to cancel a download of a bigger file.
If a file is small (say 20 KB) everything is fine.
If a file is 50 KB or more, when I click cancel I get:

IllegalStateException: getOutputStream() has already been called for this response

My question is why?

ps. "done streaming" is only shown with small files before a click on one of the buttons. With bigger files it is shown after I click "Open". It seems that it streams "to a certain limit" and then waits for user input. x()

code below:
in action:

response.setContentLength( (int) info.getFileSize());
setContentType(response, info); //see below

ServletOutputStream outStream = response.getOutputStream();
dao.getFileData(dataId, outStream);
syso("done streaming!")

return null;


private void setContentType(HttpServletResponse resp, FileInfo info) {
if (extension.equals("pdf")){
}else if (extension.equals("doc")){
}else if (extension.equals("txt")){
}else if (extension.equals("xls")){

resp.setHeader("Content-disposition", "attachment; filename=" + info.getFilename());
resp.setDateHeader ("Expires", (new Date()).getTime()+10000);


  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!