• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Download files from JSP

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a problem downloading files from JSP.
I have use this code to do it:
<%
FileName="prueba9.pdf";
File fichero = new File(FileName);
OutputStream outStream = response.getOutputStream();
BufferedInputStream fileInput= new BufferedInputStream(new FileInputStream(fichero));
response.setContentType("application/pdf");
response.setHeader("Content-Disposition","attachment;filename=prueba9.pdf");

byte [] arrayBytes = null;
int data;
int length = (int)fichero.length();
arrayBytes = new byte[length];
while((data = fileInput.read(arrayBytes, 0, array.length))!=-1) {
outStream.write(array, 0, data);
}
fileInput.close();
outStream.close();
%>
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
Amaia aoroldan@teleline.es
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
Bill
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic