无法下载IE8中的XML文件 - 弹簧3应用

问题描述:

我知道这个问题会被问了几个时间,但还是我没有得到任何解决这个问题..无法下载IE8中的XML文件 - 弹簧3应用

我想这两个浏览器IE8,Mozilla的到强制下载XML文件作为附件。但Mozilla在浏览器本身打开XML文件,IE8也尝试在屏幕上呈现XML文件,但渲染不正确。

这是我在spring 3控制器中的代码。

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(); 

注:在浏览器中,我第一次做JS验证,然后使用jQuery

function validate() { 
    //validate form 
    if(noerror) { 
     $("form").submit(); 
    } 
} 

附加请求和响应头我可以在萤火看到

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 

请告诉提交表单我如何强制这两个浏览器下载此文件。

+0

什么服务器实例在运行弹簧控制器? – 2012-02-03 10:05:31

+0

@Sean Blaney ...它的Apache tomcat 6.0..any解决方案你知道.. – Rajesh 2012-02-03 10:25:06

+0

你是否启用了mod_headers - 如果没有设置来自tomcat的头文件,很可能会以静默方式失败。 – 2012-02-03 10:34:20

在发送数据之前,您是否需要设置标题? I.E.

response.setContentType("application/octet-stream");  
response.setHeader("Content-Disposition", 
        "attachment;filename=" + export.getFlatFileName()); 
IOUtils.copy(export.getFlatFile().getBinaryStream(), response.getOutputStream()); 
+0

你是awsome..simly惊人..感谢...这么简单和最好的解决方案.. – Rajesh 2012-02-04 07:42:49