2

I am try to show an pdf in jsp page without saving this in the hard disk. I was able to generate a pdf and I tested it by saving it in hard disk. I am using DynamicJasper as reporting engine.

Here is my strut.xml for dynamic-jasper:

<action name="myJasperTest" class="com.via.qcm.view.JasperAction">
  <result name="success" type="dynamic-jasper">
    <param name="dynamicReport">DynamicReport</param>
    <param name="layoutManager">classic</param>
    <param name="parameters">dynamicReportDs</param>
    <param name="documentName">report</param>
    <param name="contentDisposition">application/download</param>
    <param name="format">PDF</param>
  </result>

I am generating pdf and saving it in ByteArrayOutputStream().

baos = new ByteArrayOutputStream();
//export to pdf
Exporter.exportToPdf(jp, baos);

Now my question is how to show this "baos" in webpage as pdf?

Alex K
  • 22,315
  • 19
  • 108
  • 236
Lipu
  • 607
  • 1
  • 5
  • 17
  • 1
    Woah, accepted after 8 months, nice :] ... see you in 8 months from now for the upvote too :D – Andrea Ligios Dec 19 '13 at 11:12
  • no man I actually did not know this feature of accept answer in that time. It was my first question in this website so please.. and I am sorry I dont have enough reputation to upvote :-( – Lipu Dec 19 '13 at 11:39
  • Don't worry, just kidding ;) P.S: you *do* have the reputation to upvote... it is 15 – Andrea Ligios Dec 19 '13 at 11:40

1 Answers1

1

There are two problems:

  • you need to return a DynamicReport object, not an Byte Array;
  • the dynamicReport variable must start with a lowercase letter:

In Struts.xml

    <param name="dynamicReport">dynamicReport</param>

In the Action

public DynamicReport getDynamicReport(){
    DynamicReport dynamicReport = null;
    // do all your stuff
    return dynamicReport;
}
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243