• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

download link in jsp ?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
kamesh aru
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic