Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

downloading a zip file in JSP

 
nelliyan ramanathan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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");
 
Ramaswamy Srinivasan
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nellian,

I think this might help you to find.

Check Here

Cheers,
Swamy
 
pradeep jaladi
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • 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
 
Maki Jav
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • 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!
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • 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
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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: 445
  • Mark post as helpful
  • send pies
  • 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 Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who's code is this?
Is it ok to distribute it like this?
 
Maki Jav
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • 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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64701
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic