This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to download multiple files in a jsp without Zipping them

 
hitendra sunkara
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20771
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18025
47
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
hitendra sunkara
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah,i have tried using ajaxCall.But i prefer Zip.

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic