1

I am trying to implement a function where on a page like this you first select the records to export/download, after clicking download button and fetching records from db, the information will be saved in two ways:

  1. for text info, they will be written in a xls file together and then downloaded
  2. for pics, they will be packed in a zip file first and downloaded.

Front-end request is formed in this way

var form = $("form");
form.css(...)
    .attr("target","_blank")
    .attr("method","post")
    .attr("action","export")
    ....
    .submit()

For back-end, I used HttpServlet with some routine operations like

response.setContentType();
response.setHeader("Content-Disposition","attachment;filename"+fileName+".zip");
out = response.getOutputStream();
out.write(buffer,0,b);

in zip download, also ZipOutputStream was used like

zipos = new ZipOutputStream(new BufferedOutputStream(response.getOutputStream()))
...
zipos.putNextEntry(new ZipEntry(...))

When I test the two downloads separately, it worked fine for excel but for Zip file I was shown error like this. When I tried to test with two form.submit() requests, only the first one will be responsed.

Here are my questions:

  1. What's reason for error in zip file? I tried to setContentType to "multipart/form-data","zip","gzip","application/octet-stream". Neither worked.
  2. Does my way for two sole requests make sense? What's the best way to realize the two/multiple file download functionality?

Thanks.

DXC
  • 21
  • 1

0 Answers0