File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Trying to use JSP to force file download.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Trying to use JSP to force file download.." Watch "Trying to use JSP to force file download.." New topic
Author

Trying to use JSP to force file download..

Chris Czegel
Greenhorn

Joined: Aug 28, 2003
Posts: 1
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trying to use JSP to force file download..