gpt4 book ai didi

java - 下载文件以使用 richfaces 和 IE8

转载 作者:行者123 更新时间:2023-12-01 15:34:10 25 4
gpt4 key购买 nike

this question 所示,我让页面可以在 Firefox、Chrome、IE9 中工作,...

但是,IE8 无法运行。我收到一个错误弹出窗口:

Internet Explorer cannot download [filename].jsp from [server].

Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Pleas try again later.

我的代码如下:

    public String downloadFile() { // called from a h:commandLink
String filename = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("file");
File file = new File(filename);
HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();

writeOutContent(response, file);

FacesContext.getCurrentInstance().responseComplete();
return "REFRESH";
}

private void writeOutContent(final HttpServletResponse res, final File content) {
if (content == null) {
return;
}
try {
res.setHeader("Pragma", "no-cache");
res.setDateHeader("Expires", 0);
res.setHeader("Content-Disposition", "attachment; filename=\"" + content.getName() + "\"");
ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
String contentType = servletContext.getMimeType(content.getName());
if (contentType == null) {
contentType = "application/octet-stream";
}
res.setContentType(contentType);
FileInputStream fis = new FileInputStream(content);
ServletOutputStream os = res.getOutputStream();
int length = 0;
int data = fis.read();
while (data != -1) {
length += 1;
os.write(data);
data = fis.read();
}
fis.close();
res.setContentLength(length);
os.flush();
os.close();
} catch (final IOException ex) {
Logger.getLogger(ApplicationController.class.getName()).log(Level.SEVERE, null, ex);
}
}

我唯一能想到的是,我在将文件写入输出流后设置响应内容长度,但正如我所说,它在现代浏览器中完美运行。

问题是,IE8 中也存在一些我们无法消除的 JavaScript 错误。尽管存在错误,但页面的其余部分似乎仍然有效。错误为“SimpleTogglePanelManager 未定义”和 2x“预期对象”。

最佳答案

根据this Microsoft KB article这是设计使然。

The problem occurs if the server is using Secure Sockets Layer (SSL) and has added one or both of the following HTTP headers to the response message:

Pragma: no-cache

Cache-control: no-cache,max-age=0,must-revalidate

删除了 res.setHeader("Pragma", "no-cache"); - 按预期工作。

另请参阅 question and answer .

关于java - 下载文件以使用 richfaces 和 IE8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9173124/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com