I’ve a Servlet that makes and returns a zip file
Something like this
response.setHeader("Pragma","Public");
response.setHeader("Cache-Control","must-revalidate,post-check=0,pre-check=0");
response.setContentType("application/octet-stream");
response.setHeader("Expires", "0");
response.setHeader("Content-Transfer-Encoding", "binary");
if(file.getName().contains("–")){
response.setHeader("Content-Disposition", "inline; filename=\"file.zip\"");
}
OutputStream os = response.getOutputStream();
ZipOutputStream zos = new ZipOutputStream(os);
for (File f : files) {
//add files, it's working...
}
bis.close();
fis.close();
zos.closeEntry();
}
zos.flush();
zos.close();
os.flush();
os.close();
Currently to download I’m using a iframe, so I set src attribute to start download.
The download frame loads when call this function
function loadIDownloadFrame(url) {
document.getElementById("idownloadFrame").src=url;
}
But now, I need show a message after return the zip file without leaving current page. I need to know if the servlet returned the zip file.
I tried get iframe status with “window.frames[‘idownloadFrame’].document.readyState”, but always status is “complete”.
Anyone have any solutions?
I think you could directly refer to download link to mapped Servlet(which returns the downloadable binary). It would not change the page if you set appropriate header in the mapped servlet to return the binary, from the code snippet it looks like you are doing that already. Why do you have to have file download in a different iframe? You don’t necessarily need that.
Where do you have to show the message? Like a JavaScript alert or something?