1

我有一个 Struts 动作,写HttpServletResponse如下。代码仅适用于 HTTP,但不适用于 HTTPS。

BufferedInputStream in = null;
try {
    response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\";");
    // set response headers
    response.setContentLength(fileData.length);
    response.setContentType("application/octet-stream");

    //BUFFER
    int bufferSize = 2 * 1024 * 1024;
    in = new BufferedInputStream(new ByteArrayInputStream(fileData), bufferSize);
    byte[] buffer = new byte[bufferSize];
    int len = 0;

    // Loop through the input file and get the data chunks...
    while ((len = in.read(buffer, 0, bufferSize)) != -1) {
        response.getOutputStream().write(buffer, 0, len);
    }
} catch (Exception e) {
    throw new SystemException(e.getMessage());
} finally {
    response.getOutputStream().flush();
    response.getOutputStream().close();
}

服务器是 Weblogic 10(有关系吗?)。整个 Web 应用程序都使用 HTTPS,但文件下载除外。它适用于 Chrome 和 FF,但不适用于 IE 8/9。以下消息显示在警告框中

Windows 找不到“https://xxxxxxx”

4

1 回答 1

4

这是一个已知的 IE 特定问题,另请参阅 Microsoft 支持站点:Internet Explorer 无法从 SSL 网站打开 Office 文档。要修复它,您需要在响应中显式设置以下标头:

response.setHeader("Cache-Control", "public");
response.setHeader("Pragma", "public");
于 2013-01-08T00:12:23.333 回答