• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

downloading a zip file in JSP

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I want to download a zip file through a jsp.The file is placed in the Project folder(where the jsp and the corresponding servlets are placed). The parameters that are given as input to JSP are the filename and the path.
The following is the code i tried but,that downloads a junk file.

Can anyone help me to resolve this..

String filelist = (String)request.getAttribute("filename");

// String fileName = "005C061S200409.zip";

String encodeUrl = null;

String path = "/configuration/downloadfile/";

System.out.println("The path is "+path);

String filedownload = path + filelist;

System.out.println("The downloadFile is "+filedownload);

encodeUrl = response.encodeURL (filedownload);

System.out.println("The encodeUrl is "+encodeUrl);

// response.setHeaderi ("Content-Disposition", "inline;filename=\"" + encodeUrl);

// response.setContentType ("application/text; charset=UTF-8");

response.setHeader ("Content-Disposition", "inline;fileName=\"" + encodeUrl);

response.setContentType ("application/zip; charset=UTF-8");
 
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nellian,

I think this might help you to find.

Check Here

Cheers,
Swamy
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The url provided by swamy is help ful. if any body wants to try another option their on api java.util.zip API in java in that we can do upload and down load of zip files.

Create one java file which uses zip api and include it in ur JSP file. Then u can upload or download the file normally.

Cheers,
Pradeep.J
 
Ranch Hand
Posts: 473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No matter what language you r using, download is the same. Just point to your
in <a href></a> tag of html and as the user clicks it, It is downloaded. The auto start version just sends request to a file path and the file download window pops up automatically.

For the upload version, I will ask the reliablity of the claim the microsoft site seems to make (see link above) that File upload support is not there in JSPs/Servlets.

False notions must not be spread!

Maki Jav

ps. I will come up with the code for file upload too! The notion presented at microsoft site is that upload is not there and we have to use third party components for it and that in ASP.net it is very easy! Stop your non-stop campaign plz!
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The reason your attempt to output a ZIP file from JSP using;

resulted in garbage is that ZIP files are in binary format while JSP are designed to always send characters. If for some reason you can't use a link to a file and you need to send binary data under program control, you should use a servlet.
Bill
 
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

For the upload version, I will ask the reliablity of the claim the microsoft site seems to make (see link above) that File upload support is not there in JSPs/Servlets.

False notions must not be spread!
Maki Jav

ps. I will come up with the code for file upload too! The notion presented at microsoft site is that upload is not there and we have to use third party components for it and that in ASP.net it is very easy! Stop your non-stop campaign plz!




It's actually not a false notion.
However, there are excellent 3rd party (Open Source) solutions out there.

http://jakarta.apache.org/commons/fileupload/
[ December 28, 2004: Message edited by: Ben Souther ]
 
Maki Jav
Ranch Hand
Posts: 473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Bear edit: posting of legally questionable code removed.]
[ February 09, 2005: Message edited by: Bear Bibeault ]
 
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
Who's code is this?
Is it ok to distribute it like this?
 
Maki Jav
Ranch Hand
Posts: 473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Sorry but I could not find any license agreement for this code.
I hope that it is legal to use it.

Maki Jav
[ February 09, 2005: Message edited by: Maki Jav ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maki, if you do not have clear license to post code, please do not post it on the JavaRanch.

Thanks
bear
Forum bartender
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic