Tried to zip multiple files on the fly in java servlet with zip package (ZipOutputStrea m), so users can download the zip file by calling the servlet. It works fine for small files. But occasionally the browser stops the download before completion when users invoke the servlet action, and the zip file downloaded is corrupted.

The servlet response header “content length” is not set, since the zip file is generated on the fly and...