Downloading a file from a server is trivial and so is the implantation of it using httpservletresponse. But after fighting with for a long time I finally came across this jQuery plugin. This works well as long as we make HTTP request using GET or POST to server and the server responds with a file to download.
and you’re done!
Of course, if the server doesn’t send the correct response, it wouldn’t work. These are the list of headers that I used for the response sent from the server.
// get your file as InputStream InputStream is = ...; // copy it to response's OutputStream IOUtils.copy(is, response.getOutputStream()); response.flushBuffer(); // set headers response.setContentType("application/pdf"); // Your content type response.setHeader("Content-Disposition", "attachment; filename=somefile.pdf");