java servlet :: how to download multiple files

A

anil001

my requirement is to download multiple files on click of submit button.
At present the following code sniplet downloads single files
 
B

biro

my requirement is to download multiple files on click of submit
button.
At present the following code sniplet downloads single files
----------------------------------------------------------------
response.setContentType("application/download");
response.setHeader("Content-disposition","attachment; filename=" +
strAttachName);
response.getOutputStream().write(ByteArray());


If you mean you want the server to send the user several files after they
click submit once, then I don't think its possible.
 
S

Steve Claflin

biro said:
If you mean you want the server to send the user several files after they
click submit once, then I don't think its possible.

I'm also pretty sure that the way http works you can send only one
response; since a response corresponds to a file for a download, that
would mean you could send only one file.

For the content type you have listed, it seems that you would want to
put them all into a zip file and just send that. But, if it's supposed
to be dynamic content, you probably wouldn't want to have all possible
combinations of files stored in advance. If you want to build the zip
on the fly, see: http://www.mike-levin.com/java/zipoutputstream.html .

Otherwise, you could return an html page that lists all the individual
files as links, and let the user manually download each one (or come up
with a scheme that automates that process).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top