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

HTTP Header

Created by mpecher. Last edited by mpecher, 6 years and 149 days ago. Viewed 1,710 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");
no comments | post comment

Menu:
Java & J2EE
Development
Books

Help:
Help FAQ
Formatting


< May 2012 >
SunMonTueWedThuFriSat
12345
6789101112
13141516171819
20212223242526
2728293031


Logged in Users: (0)
… and 2 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.