Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Trying to use JSP to force file download..  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • 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");
"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!
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!