[ start | index | login ]
start > Development > HTTP Header

HTTP Header

Created by mpecher. Last edited by mpecher, 6 years and 38 days ago. Viewed 1,702 times. #4
[diff] [history] [edit] [rdf]
labels
attachments

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");
Please login to post a comment.

Menu:
Java & J2EE
Development
Books

Help:
Help FAQ
Formatting


< February 2012 >
SunMonTueWedThuFriSat
1234
567891011
12131415161718
19202122232425
26272829


Logged in Users: (0)
… and 10 Guests.



Disclaimer: Views and opinions are that of the individual author, and not that of Marand Custom Solutions. This site is an open forum for technical content, and the company accepts no liability for any content or view expressed.