1

我想从 DWR 调用中打开一个 pdf 文件。我正在使用 DWR 2.0 请指导我。

4

2 回答 2

1

我不明白你的意思是什么open pdf file。根据我对您问题的理解,您可以使用 DWR 将 pdf 文件从服务器获取到客户端。然后你必须用任何客户端技术来显示它。

在 DWR 网站你可以找到 dwr.war 文件。它包含一个下载 pdf 文件的示例。您已将该文件放在任何 servlet 容器的 web-apps 文件夹中。然后您可以通过 访问教程http://localhost:8080/dwr/

于 2010-11-12T19:42:49.863 回答
1

考虑升级到 DWR 3。

在 DWR3 中,您将找到一个 FileTransfer 对象...

HTML:

<form action="downloadFile.do">
  <div id="buttons">
    <input type="button" value="Back" id="mapback"    onClick="javascript:back();" class="Back" />
    <input type="button" value="SavePDF" id="SavePDF" onclick="return downloadPdfFile();" class="saveToPdfButton" />
    <input type="submit" value="Continue" id="continue" class="continue" />

  </div>
</form>

JavaScript:

function downloadPdfFile() {
  dwr.engine.setTimeout(59000);

  var callMetaData = {
  callback : downloadPdfCallback,
  exceptionHandler : hideLoadingAndSwitchOnSavePDFButton,
  errorHandler : hideLoadingAndSwitchOnSavePDFButton,
  preHook : showLoading,
  postHook : hideLoading
};

DWRAction.downloadPdfFile(callMetaData);

return false;
}

function downloadPdfCallback(data) {
   dwr.engine.openInDownload(data);
}

爪哇:

File pdfFile = new File(pdfFilename);
try {
      InputStream is = new BufferedInputStream(new FileInputStream(pdfFile));
       dwrPdfFile = new FileTransfer(pdfFile.getName(), "application/pdf", is);
     } catch (FileNotFoundException e) {
       LOGGER.error("Unable to find PDF file \'{}\'", pdfFile.getAbsoluteFile());
     } 
于 2012-08-22T09:26:08.660 回答