File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Trying to use JSP to force file download..

Chris Czegel

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");
"attachment; filename=\""
+ filename + "\""); fileInputStream =
+ filename);
int i;
while (( != -1) {



<xtags:style xml="<%=xmlDoc%>" xsl="xsl/sigGallery.xsl"/>
Anyways any help that you guys could give would be MUCH appreciated!
I agree. Here's the link:
subject: Trying to use JSP to force file download..
It's not a secret anymore!