Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

download link in jsp ?

 
manojdesai sompadi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have to put a doanload link in a jsp page
<a href="/test/xyz.zip"></a>

but i have the xyz file in local drive c:\\download\xyz.zip
i am generating the file in local folder i can't put it in the server root.
how to map the download file from local drive to server path without copying the file into server path ?
thanks in advance
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would need to write a servlet that sets the content-type, sets the content-disposition, and then streams the file to the browser.
 
manojdesai sompadi
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the response
fallowing code modified from the example you have reffered when i am running this servlet its opening a download dialog box asking for downloading the servlet.java file instead of java.zip file ?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is your code even finding the file?

On line 4, you're saying: filename = "c:\\file.zip".
On line 17, you're saying: getResourceAsStream("WEB-INF" + filename));

This would mean that your looking for a file with a path and filename of:
"WEB-INFC:\\file.zip"

If the file is not inside your webapp, you would get the input stream with:
FileInputStream in = new FileInputStream(new File(filename));

"context.getResourceAsStream" is for files that are inside your webapp.
 
kamesh aru
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the answer .
its working now but the save dialogbox i am getting the servlet name as default name to save ,instead of it how to get the test.zip file name as deafult name .
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The content-disposition header is where you set the desired name for the file.
 
kamesh aru
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i will try it
thanks for your prompt responces.
i appreciate your help
thanks once again
 
kamesh aru
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have set the name in Content-Disposition
as fallows
resp.setHeader(filename,"inline;filename=\""+filename +"\"");
by this i could get the file extenison correctly but still name of the file it takes as name of servlet.
advice
 
kamesh aru
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i commented the line
resp.setHeader(filename,"inline;filename=\""+filename +"\"");
i am getting same result .
why application is not picking up setHeader ?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
kamesh aru
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i changed the content type to
contentType = "application/x-zip";
resp.setHeader("Content-Disposition",
" inline; filename=" + filename);
then its working

thanks for the responces till now they are very helpful to me
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic