• 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

Trying to use JSP to force file download..

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey everyone..
kinda new to jsp, and I am having a bit of trouble getting this code to work. Basically, I am creating an image gallery, and the user needs to be able to download a file by clicking on the link, even if the file is a .jpeg or another file that usually opens in a browser. I am using jsp and xml/xslt.
The way I have been trying to do it, is to have a form on my xslt page that submits back to my index.jsp page. The problem, is that once I hit the download button (to submit the form) on my page, it tries to force the download of the index.jsp file, and not the file I am specifying. Take a look at the code below (from my index.jsp page) (i have tested all the variables and they are working):
<%
String hasSubmitted = request.getParameter("hasSubmitted");
if (hasSubmitted != null) {
String filepath = request.getParameter("getPath");
String filename = request.getParameter("getFile");
response.setContentType(
"APPLICATION/X-DOWNLOAD");
response.setHeader("Content-Disposition",
"attachment; filename=\""
+ filename + "\"");
java.io.FileInputStream fileInputStream =
new java.io.FileInputStream(filepath
+ filename);
int i;
while ((i=fileInputStream.read()) != -1) {
out.write(i);
}
fileInputStream.close();
out.close();


}

%>

<xtags:style xml="<%=xmlDoc%>" xsl="xsl/sigGallery.xsl"/>
Anyways any help that you guys could give would be MUCH appreciated!
Thanks!
Chris
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic