Download a file from Servlet using Ajax

You can’t “download a file using AJAX”. AJAX is about downloading data from a server for JavaScript to process.

To let the user download the file either use a simple link to the file/servlet, or if you really, really need to use JavaScript, then assign the URL to document.location.href.

Also you need to make sure that the server (or in this case the servlet) sends the appropriate MIME type, in case of a ZIP file most likely application/zip.

Leave a Comment