Want to open PDF file from DWR request

梦想的初衷 提交于 2019-12-11 12:13:09

问题


I want to open a pdf file from DWR call. I am using DWR 2.0 Please guide me.


回答1:


I am not able to understand that what do you mean by open pdf file. AS per my understanding of your question, you can use DWR to get the pdf file from server to client side. Then you have to display it with any client side techniques.

In DWR website you can find dwr.war file. It contains a example for downloading pdf files. You have put that file in any servlet container's web-apps folder. Then you can access the tutorial through http://localhost:8080/dwr/.




回答2:


Consider upgrading to DWR 3.

In DWR3 you will find a FileTransfer object...

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);
}

Java:

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());
     } 


来源:https://stackoverflow.com/questions/4087873/want-to-open-pdf-file-from-dwr-request

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!