aspose file tools*
The moose likes JSP and the fly likes how to download multiple files in a jsp without Zipping them Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "how to download multiple files in a jsp without Zipping them" Watch "how to download multiple files in a jsp without Zipping them" New topic
Author

how to download multiple files in a jsp without Zipping them

hitendra sunkara
Ranch Hand

Joined: Jul 25, 2013
Posts: 35
Hi ,

I need to download multiple files from my jsp,My jsp will receive a string array,and in that each array will have a filePath.I ggot the solution to download multiple files by Using ZipOutPutStream,But i don't want to Zip Them,I need to download them in a folder.In that folder i should have all the files.

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Apart from the bad taste involved in using a JSP to do a file download, the fact is that an HTTP response cannot contain more than one file unless those files are wrapped in some suitable wrapper. A Zip archive is a suitable wrapper. A "folder" -- well, there's no such MIME type. What's your reason for not wanting to use a Zip archive?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16068
    
  21

Expanding on on Paul's explanation, HTTP is a 1-to-1 request/response protocol. You send 1 request, which is a URL GET, POST, or whatever, and the server returns 1 response, which can be a "file", a web page, or whatever.

You cannot return multiple responses from a single request, and you DEFINITELY cannot have your server select a directory on the client computer's disk drive and write a file into it. A file download is just an HTTP response data stream that has certain characteristics designed to alert the client to the need to save the response contents as a file instead of doing something like displaying it as a web page. The client will then display a dialog asking the user what directory that response should be written into as a file.

There is a reason for the dialog. It ensures that malicious servers cannot insert or replace critical system files with viruses. And it means that the server doesn't have to know anything about the client's filesystem or filesystem organization. I'm using a Linux machine, and there is no such thing as a "C" drive on Linux, any more than there is in IBM's z/OS. The web isn't a file server, after all.

You could automate the process of multiple file downloads by adding AJAX logic to the page that does the download request so that within that page, a succession of AJAX http request/response cycles are initiated, one for each file. But even then, the user will be prompted for the download directory on each file, due to the security constraints I mentioned earlier, commonly known as the "sandbox". A digitally-signed client-side logic module can avoid that, but that's not something you want to do lightly. It's usually very confusing and messy to get a client to accept a signed logic module. Microsoft ActiveVirus[TM] excepted.


Customer surveys are for companies who didn't pay proper attention to begin with.
hitendra sunkara
Ranch Hand

Joined: Jul 25, 2013
Posts: 35
Yeah,i have tried using ajaxCall.But i prefer Zip.

Thanks
 
wood burning stoves
 
subject: how to download multiple files in a jsp without Zipping them