aspose file tools*
The moose likes JSP and the fly likes downloading a zip file in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "downloading a zip file in JSP" Watch "downloading a zip file in JSP" New topic
Author

downloading a zip file in JSP

nelliyan ramanathan
Greenhorn

Joined: Sep 11, 2004
Posts: 2
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

Joined: Aug 31, 2004
Posts: 295
Hi Nellian,

I think this might help you to find.

Check Here

Cheers,
Swamy
pradeep jaladi
Ranch Hand

Joined: Nov 21, 2004
Posts: 65
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


Pradeep.Jaladi
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 436
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!


Help gets you when you need it!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
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

Joined: Dec 11, 2004
Posts: 13410

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 ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 436
[Bear edit: posting of legally questionable code removed.]
[ February 09, 2005: Message edited by: Bear Bibeault ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Who's code is this?
Is it ok to distribute it like this?
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 436
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

Joined: Jan 10, 2002
Posts: 61417
    
  67

Maki, if you do not have clear license to post code, please do not post it on the JavaRanch.

Thanks
bear
Forum bartender


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: downloading a zip file in JSP