Prompt for download of a file
To automatically have the browser prompt to download a file, the contentType needs to be set in the HTTP Header:
response.setContentType(application/csv);
(csv used an an example here)
Binary/other files
response.setContentType("application/octet-stream");
May also want to set the length of the file (if known)
response.setContentLength((int) f.length());
Setting the filename for a Download
Setting the filename of a file that is downloaded is achieved by setting the following in the HTTP Header:
response.setHeader("Content-Disposition", "attachment; filename=TheFileName.txt"); Internet Explorer download issues
Internet Explorer has a bug when downloading files through SSL. In this case for IE/Windows set additional:
response.setHeader("Cache-Control", "must-revalidate");
response.setHeader("Pragma", "public");