• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

how to download multiple files in a jsp without Zipping them

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Sheriff
Posts: 28394
100
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Saloon Keeper
Posts: 28654
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Nag Venkat
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah,i have tried using ajaxCall.But i prefer Zip.

Thanks
 
reply
    Bookmark Topic Watch Topic
  • New Topic