• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Write file to browser tomcat error

 
Sue Stephen
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am using the code below in a servlet to write a jar file to the browser so that user can download it. However, after the user hit download to save the file, the tomcat server display an error caused by flushing the buffer. Does anyone know why it happens? Thank you for your help

-------------------------------------------------------
try{
String disHeader = "Attachment;Filename=\"" + jarName +"\"";
response.setHeader("Content-Disposition", disHeader);
response.setContentType("APPLICATION/OCTET-STREAM");

FileInputStream fileInputStream = new FileInputStream(jarFile);

int i;
while ((i=fileInputStream.read())!=-1)
{
out.write(i);
}
fileInputStream.close();
out.close(); //This line gives the problem
}

catch(Exception e) // file IO errors
{
System.out.println("######### file error");
e.printStackTrace();
}
--------------------------------

error:

org.apache.jasper.runtime.PageContext: Internal error flushing the buffer in release()
 
Sue Stephen
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, it actually is a jsp page to write to the browser.
 
James Carman
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The servlet engine will close the output stream for you automatically. This sort of logic should go in a servlet of course.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, the "out" object is a printWriter which is meant for writing text streams not binary files. For that you will need a servletOutputStream.

And I agree, you don't want to do this from a JSP.

Why can't you just provide a link to it?
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic