1

I am using the Jasper Reports framework along with my Struts2 web app . It was only sometime back that I realised JasperViewer wouldn't help me display and download my report in the Client browser. I saw up a few links and almost all told me to use Servlets and OutputStreams to do this.I tried this link for getting the Servelet request and response to my Java class. I am quite new to this ,so various attempts of using code to do so from these sources this etc didn't work. This is why I am posting this for help.

The relevant code for my Action class method is

public String execute() throws Exception //the method which will be executed
{
                ...
                request=ServletActionContext.getRequest();
                response = ServletActionContext.getResponse();
                if(response!=null)
                    System.out.println("Response is not null");
                System.out.println("coming to this method");
                java.io.InputStream in = this.getClass().getClassLoader().getResourceAsStream("com/ram/report/jasper/Report.jrxml");
                JasperReport jasperReport=JasperCompileManager.compileReport(in);
                HashMap<String, Object> params = new HashMap<String, Object>();             
                JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params,new JRBeanCollectionDataSource(list));
                JRPdfExporter pdfExporter = new JRPdfExporter();
                List<JasperPrint> jasperPrintList= new ArrayList<JasperPrint>(); 
                jasperPrintList.add(jasperPrint);
                pdfExporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST,jasperPrintList);
                pdfExporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME ,request.getRealPath("")+"/Report.pdf");
                pdfExporter.exportReport();

            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            return "ajaxReturn";
        }
        }
            return "success";
    }   

My action (from which struts.xml is linked to)

<action name="reportData" class="Reportfetchnew">
        <interceptor-ref name="cookie"></interceptor-ref>
         <interceptor-ref name="cookieProvider"></interceptor-ref>
         <interceptor-ref name="defaultStack"></interceptor-ref>
        <result name="success">htdocs/jsp/report_new/report_tool.jsp</result>
         <result name="ajaxReturn" type="stream" >
            <param name="contentType">application/pdf</param>
            <param name="inputName">in</param>
            <param name="bufferSize">1024</param>

            </result>

        </action>

I am getting this error

Exception occurred during processing request: Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.
java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the <param name="inputName"> tag specified for this action.

The problem was that before this, when I viewed my Jasper file using JasperViewer, it was working fine. What should I do to workaround this error and get my pdf available to download ?

Community
  • 1
  • 1
Rameshwar Bhaskaran
  • 345
  • 1
  • 4
  • 16

0 Answers0