Java 无法在IE8--spring 3应用程序中下载XML文件
我知道这个问题会被问好几次,但我仍然没有找到解决这个问题的办法 我希望浏览器IE8和Mozilla都能强制下载XML文件作为附件。但Mozilla会在浏览器中打开XML文件,IE8也会尝试在屏幕上呈现XML文件,但呈现不正确 这是我在Spring3控制器中的代码Java 无法在IE8--spring 3应用程序中下载XML文件,java,jquery,download,Java,Jquery,Download,我知道这个问题会被问好几次,但我仍然没有找到解决这个问题的办法 我希望浏览器IE8和Mozilla都能强制下载XML文件作为附件。但Mozilla会在浏览器中打开XML文件,IE8也会尝试在屏幕上呈现XML文件,但呈现不正确 这是我在Spring3控制器中的代码 Pmd17Export export=exportService.getFlatFile(dbdto.getExportFileId()); IOUtils.copy(export.getFlatFile().getBinaryStre
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();
}
}
附加我在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
请告诉我如何强制两个浏览器下载此文件。在发送数据之前,您不需要设置标题吗?即
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition",
"attachment;filename=" + export.getFlatFileName());
IOUtils.copy(export.getFlatFile().getBinaryStream(), response.getOutputStream());
您正在哪个服务器实例上运行spring控制器?@Sean Blaney…其Apache tomcat 6.0..您知道的任何解决方案..您是否启用了mod_头文件-如果不从tomcat设置头文件,则很可能会自动失败。@Sean Blaney如何在tomcat中启用mod_头文件?无法在IE中下载xml文件,至少mozilla在屏幕上正确地呈现了xml,但IE根本没有在屏幕上正确地呈现它。对于IE,屏幕仍然是空的,使用IE开发工具,我可以在正文中看到有线xml格式。我的意思是html的body标记存储xml文件的某些片段…和response.setContentType(“内容处置”),“attachment;filename=”)…根本不起作用,就好像响应头没有被更改一样。。