简体   繁体   English

如何使Struts2在浏览器中加载动态生成的pdf文件

[英]How to make struts2 load a dynamically generated pdf file in browser

I am using Struts2 framework for my webapp. 我正在为我的web应用程序使用Struts2框架。 The idea is that user select dates for which he wants report. 这个想法是用户选择他想要报告的日期。 depending on these details a pdf report is generated on the fly. 根据这些详细信息,可动态生成pdf报告。 Upto this point everything is working fine as expected. 到目前为止,一切都按预期工作。

But I want to open the generated report in the browser. 但是我想在浏览器中打开生成的报告。 How can I do that?? 我怎样才能做到这一点?? Thanks in advance. 提前致谢。

You have two options: 您有两种选择:

  1. Use JasperReports struts2 plugin and then have a new jasperreport result type 使用JasperReports struts2插件,然后使用新的jasperreport结果类型
  2. Use the stream result type and have in your action an InputStream property to pass to the stream result type configuration, toghether with MIME type (application/pdf in your case) and file name. 使用流结果类型,并在您的操作中将InputStream属性与MIME类型(在您的情况下为application / pdf)和文件名一起传递给流结果类型配置。 Yopu will set in your action the InputStream to a stream containing your PDF bytes Yopu将在您的操作中将InputStream设置为包含您的PDF字节的流

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM