I know this question would have been asked several time but still I am not getting any solution to this problem..
I want both browser IE8, Mozilla to force download XML file as an attachment. But Mozilla opens the XML file in the browser itself and IE8 also try to render XML file on screen but render it incorrectly.
Here is my code in spring 3 controller.
Pmd17Export export=exportService.getFlatFile(dbdto.getExportFileId());
IOUtils.copy(export.getFlatFile().getBinaryStream(), response.getOutputStream());
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition",
"attachment;filename=" + export.getFlatFileName());
response.flushBuffer();
Note : In browser I am first doing js validation then Submitting the form using jquery
function validate() {
//validate form
if(noerror) {
$("form").submit();
}
}
Attaching request and response header what i can see in firebug
Response Headersview
Date Fri, 03 Feb 2012 12:55:42 GMT
Server Apache-Coyote/1.1
Transfer-Encoding chunked
Request Headersview
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Encoding gzip, deflate
Accept-Language en-us,en;q=0.5
Connection keep-alive
Cookie JSESSIONID=5ED81A79A2297AD044E6DBB2B90806E7
Host localhost:8080
Referer http://localhost:8080/dbcomparision/app/exportdatabase.html
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:9.0.1) Gecko/20100101 Firefox/9.0.1
Request Headers From Upload Stream
Content-Length 15
Content-Type application/x-www-form-urlencoded
Please tell me how can I force both browser to download this file.
Don’t you need to set the headers before you send the data? I.E.