0

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

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 下运行的事实有关。这有帮助吗?

4

1 回答 1

-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 无法下载 https://something。如果您使用 https 并阻止缓存,下载将失败。

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

 Cache-Control: private, max-age=15
于 2012-06-27T19:50:26.300 回答