简体   繁体   English

IE8中的下载文件代码失败但在IE9中有效

[英]download file code fails in IE8 but works in IE9

I am trying to create a xls file through java code and allow user to doownload it. 我试图通过java代码创建一个xls文件,并允许用户下载它。 The download code is in JSP and it works well in IE9 and other browsers. 下载代码在JSP中,它在IE9和其他浏览器中运行良好。 But it give error in IE 8 as "Unable to dowload file. Unable to open this internet site.The requested site is either unavailable or can not be found.Please try later." 但它在IE 8中给出错误“无法下载文件。无法打开此网站。请求的网站要么不可用,要么找不到。请稍后再试。”

my JSP code is as follows. 我的JSP代码如下。

    <%@ page import="org.apache.poi.ss.usermodel.Workbook"%><%@ page import="java.io.*"%>
    <%response.setHeader("Pragma","no-cache");
    response.setHeader("Content-disposition", "attachment;filename=DataTemplate.xls");
    response.setContentType("application/vnd.ms-excel");
    OutputStream os = response.getOutputStream(); 
    ((Workbook)request.getAttribute("result")).write(os); os.flush();os.close();%>

I checked all the settings for IE as suggested by microsoft sites. 我按照微软网站的建议检查了IE的所有设置。 Suggestions from other users on internet are to re-install IE8 but it does not sound good to me as I am getting this issue on multiple machines. 来自互联网上其他用户的建议是重新安装IE8,但这对我来说听起来不太好,因为我在多台机器上遇到了这个问题。

Any help is welcome. 欢迎任何帮助。

Thanks. 谢谢。

This issue occurs if the server sends a " Cache-control:no-store " header or sends a " Cache-control:no-cache " header. 如果服务器发送“ Cache-control:no-store ”标头或发送“ Cache-control:no-cache ”标头,则会出现此问题。

One of the solution is to add Cache-Control: private to response header. 其中一个解决方案是将Cache-Control: private添加到响应头。

Also, There are few official blog on Microsoft Support. 此外,微软支持的官方博客很少。 Check these links one of them should help you to solve the problem. 检查这些链接其中一个应该可以帮助您解决问题。

http://support.microsoft.com/kb/815313 http://support.microsoft.com/kb/815313

http://support.microsoft.com/kb/323308 http://support.microsoft.com/kb/323308

Thanks Hardik. 谢谢哈迪克。 You answer helped me to solve my problem. 你的回答帮助我解决了我的问题。

I modified my code to incldue following and its working fine in IE8 and IE9. 我修改了我的代码以使其跟随并且在IE8和IE9中正常工作。

    response.setHeader("Cache-Control","private");
    response.setHeader("Pragma","private");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM