gpt4 book ai didi

struts2 - 在 Jsp 中使用 Struts2 显示 Pdf

转载 作者:行者123 更新时间:2023-12-04 18:47:26 26 4
gpt4 key购买 nike

我的问题是我无法显示使用 Struts2 在 jsp 上生成的 pdf。

我能够在 struts2 中使用 Dynamic Jasper 动态生成 pdf 并且还能够

下载它使用

result type="stream"我遇到的唯一问题是在jsp中显示pdf。我能够

使用 iframe 标签显示它,但它显示旧的 pdf 而不是我在运行时生成的那个。

如果有人有任何建议,请帮我提前谢谢

最佳答案

Action Class 

public class GeneratePdf extends ActionSupport
{
public InputStream inputStream;
File file = new File("D:\\workspace\\desktopApp\\HRIS_Updated\\WebContent\\Jasper\\hris.employee.report.AwardReport.pdf");
public String execute(){

try {

inputStream = new DataInputStream( new FileInputStream(file));

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return SUCCESS;
}
public void setInputStream(InputStream inputStream) {
this.inputStream = inputStream;
}



public InputStream getInputStream() {
return inputStream;
}
}

在 .xml 文件中
<action name="GeneratePdf" class="hris.report.action.GeneratePdf">
<result name="success" type="stream">
<param name="contentType">application/pdf</param>
<param name="inputName">inputStream</param>
<param name="contentDisposition">inline;filename="test.pdf"</param>
<param name="bufferSize">1024</param>
</result>
</action>

希望能帮助到你 :)

关于struts2 - 在 Jsp 中使用 Struts2 显示 Pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11903490/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com