This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Download files from JSP

Amaia Roldan
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem downloading files from JSP.
I have use this code to do it:
File fichero = new File(FileName);
OutputStream outStream = response.getOutputStream();
BufferedInputStream fileInput= new BufferedInputStream(new FileInputStream(fichero));

byte [] arrayBytes = null;
int data;
int length = (int)fichero.length();
arrayBytes = new byte[length];
while((data =, 0, array.length))!=-1) {
outStream.write(array, 0, data);
The problem is the file is not well downloaded, and I can't open it. The problem is only from JSP because if I use a servlet it works fine, and I CAN'T USE SERVLET.
Can anybody help me?? Thanks
William Brogden
Author and all-around good cowpoke
Posts: 13078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP are just naturally designed to serve character data, not binary. See the API section on JspWriter. I would have expected it to throw an exception at the point you do a getOutputStream since having out as an automatic variable is part of the JSP API, and out is a JspWriter.
Why can't you use a servlet?
Switching from electric heat to a rocket mass heater reduces your carbon footprint as much as parking 7 cars. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!