Struts2 StreamResult在IE8中不起作用

时间:2012-06-27 15:26:37

标签: internet-explorer struts2

我正在尝试下载位于文件系统上的PDF。我有一个动作类DownloadFileAction,它扩展了ActionSupport,基本上执行以下操作:

public String execute() {
  // lookup file
  inputStream = new FileInputStream(file);
  return SUCCESS;
}

public String getContentType() {
  return "application/pdf";
}

public String getContentDisposition() {
  return "attachment;filename=\"filename.pdf\"";
}

我的动作映射定义为您所期望的:

<action name="downloadFile" class="com.foo.DownloadFileAction">
  <result name="success" type="stream">
    <param name="allowCaching">false</param>
  </result>
</action>

这在Firefox和IE9中运行良好,但由于未知原因无法在IE8中运行。有什么想法吗?


更新:使用Live HTTP Headers插件,我在Firefox中进行下载时会看到这一点。我假设这在IE8中是相同的:

 http://fmpdmb:7001/shopping/search/printItemDetail.action?upid=41271812&OeT2rTJY=LIJ8HDLqT7igptDozBz5ocIg

 GET /shopping/search/printItemDetail.action?upid=41271812&OeT2rTJY=LIJ8HDLqT7igptDozBz5ocIg
 HTTP/1.1 
 Host: fmpdmb:7001 
 User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:13.0) Gecko/20100101 Firefox/13.0.1 
 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
 Accept-Language: en-us,en;q=0.5 
 Accept-Encoding: gzip, deflate
 Connection: keep-alive 
 Referer: http://fmpdmb:7001/shopping/search/searchResultItemDetail.action?upid=41271812
 Cookie: ADMINCONSOLESESSION=vQpcPk2N58P1QZtLrPVHyWjvS9pDmT2b60pdrpqHrBHQhjGBLmhV!-1356202776;
 EMALL-SESSION=r7FbPrmCQ1DVQt1Wkf214nznpT61L03JHhN1d7Z8TZzH5tzCXvdm!1350268378

 HTTP/1.1 200 OK
 Cache-Control: no-cache 
 Date: Wed, 27 Jun 2012 15:48:00 GMT 
 Pragma: nocache, no-cache 
 Transfer-Encoding: chunked
 Content-Type: application/pdf 
 Expires: 0 
 Content-Disposition: inline;filename="document.pdf" 
 X-Powered-By: Servlet/2.5 JSP/2.1

更新:更多信息。我认为这可能与应用程序在https下运行这一事实有关。这有帮助吗?

1 个答案:

答案 0 :(得分:-1)

动作应如下所示:

<action name="download" class="com.project.DownloadAction">
    <result name="success" type="stream">
      <param name="contentType">application/pdf</param>
      <param name="inputName">inputStream</param>
      <param name="contentDisposition">attachment;filename="download.pdf"</param>
      <param name="bufferSize">1024</param>
    </result>
   </action>

<强>更新

查看这篇文章:Internet Explorer Cannot Download https://something。如果您使用https并阻止缓存,则下载将失败。

尝试定义这样的内容可以帮助您防止错误:

 Cache-Control: private, max-age=15