在Jsp中使用Struts2显示Pdf

时间:2012-08-10 14:11:54

标签: struts2

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

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

使用

下载

结果类型=“流”我遇到的唯一问题是在jsp中显示pdf。我能够

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

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

1 个答案:

答案 0 :(得分:6)

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>

希望它有助于:)