Uploading a file with code does not work in IE8, but it works in IE9

I am trying to create an xls file through java code and allow the user to download it. The download code is in JSP and it works well in IE9 and other browsers. But it gives an error in IE 8 like "The file cannot be downloaded. This website cannot be opened. The requested site is either unavailable or cannot be found. Please try again later."

my JSP code is as follows.

<%@ 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. Other users' suggestions on the Internet is reinstalling IE8, but it doesn't seem good to me as I get this problem on multiple machines.

Any help is appreciated.

Thanks.

+4
source share
2 answers

This problem occurs if the server sends the header " Cache-control:no-store " or sends the header " Cache-control:no-cache ".

One solution is to add Cache-Control: private to the response header.

In addition, Microsoft Support has a bit of an official blog. Check out these links, one of them will help you solve the problem.

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

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

+4
source

Thanks Hardik. The answer you helped me solve my problem.

I modified my code to include the following and its work in IE8 and IE9.

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

All Articles