1
 protected void doGet(HttpServletRequest request, HttpServletResponse response) 
        throws ServletException, IOException {

    response.setContentType("application/pdf");

    ServletOutputStream servletOutputstream = response.getOutputStream();

    InputStream reportStream = getServletConfig().getServletContext().
        getResourceAsStream("/report-src/Payment.jasper");

    /* Here I am checking whether I am getting refrence of .jasper as 
    stream or not*/
    System.out.println(reportStream);

    try {
        //  Here i am establishing connection with database     

        Connection connection = Dbconn.getConnection();
        Statement stmt = connection.createStatement();

        /* Here I am fetching values using resultset with query
        as I want to give the condition in where clause. At this servlet
        which will be decided on the basis of request comes on this servlet
        so I am using object of this resultset and will  pass it as 
        parameter in the constructor of JRResultSetData    */

        ResultSet rset = stmt.executeQuery(query); 

        JRResultSetDataSource datasource = new JRResultSetDataSource(rset);

        /* In this while loop I am checking whether I am getting  
        values in ResultSet */

        while (rset.next()) {
            System.out.println(rset.getString(2));
        }

        /* Here is the main problem as I think because I am passing object
        of JRResultSet and passing this object in method to generate the report
        in pdf format */
        JasperRunManager.runReportToPdfStream(reportStream, servletOutputstream,
                new HashMap(), datasource);

        servletOutputstream.flush();
        servletOutputstream.close();
    } catch (Exception e) {
        // display stack trace in the browser
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter);
        e.printStackTrace(printWriter);

        response.setContentType("text/plain");

        response.getOutputStream().print(stringWriter.toString());
    }
}

現在、何も報告されていません。エラーも発生していません。レポートの静的データもレポートに表示されません。空のドキュメントのみが生成されています。

私はこれに多くの時間を無駄にしました、助けてください。

4

0 に答える 0