Example to read jasperreport jsp?

 I  already created the  report  with ireport but now i want read that report  in my jsp app i found this old example is using  jasperreport 2.0.4 this my code 

 

 

<%@page import="net.sf.jasperreports.engine.*" %>

            <%@page import="java.util.*" %>

            <%@page import="java.io.*" %>

            <%@page import="java.sql.*" %>

            

            <%

             

 Connection conexion ;

 

 Class.forName("org.postgresql.Driver").newInstance();

 conexion = DriverManager.getConnection("jdbc:postgresql://localhost:5432/antigua","postgres","grupo02antigua");

 

 File reportFile = new File(application.getRealPath("Empleados.jasper"));

 Map parameters = new HashMap();

 parameters.put("nombrepara", "valorpara");

 

 byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), parameters,conexion);

 

 response.setContentType("application/pdf");

 response.setContentLength(bytes.length);

 ServletOutputStream outputStream = response.getOutputStream();

 outputStream.write(bytes,0,bytes.length);

 

 outputStream.flush();

 outputStream.close();

%>

 

but is not working  

 

i already tryed          File reportFile = new File(application.getRealPath("Empleados.jrxml"));

 

and still doesnt work  so any idea where i could find  a exmaple to do this?

 

any example to read  reports  in jsp.

 

Thx

                             

 

gerson2002's picture
Joined: Nov 15 2011 - 12:29am
Last seen: 11 years 10 months ago

2 Answers:

 I use the following code to generate PDF successfully

Code:
<%
 
            Connection con=null;
 
           Mydao ad = new Mydao();
            con = ad.getConnection();
 
 
 
 
 
            Map parameters = new HashMap();
            parameters.put("param1", "PH2011-001");
 
            JasperReport report = JasperCompileManager.compileReport("demo.jrxml");
  JasperPrint print = JasperFillManager.fillReport(report, parameters, con);
 
 
 
 
 
                        String  destFile = "NAME OF PDF FILE";
 
 
                        JasperExportManager.exportReportToPdfFile(print,destFile);
                        out.println("PDF created ");
 
 
 
 
 
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title><strong class="highlight">JSP</strong> Page</title>
    </head>
    <body>
        <h1>Hello World!</h1>
    </body>
</td></tr></tbody></table>
satyadoorva's picture
Joined: Nov 7 2011 - 10:37pm
Last seen: 11 years 10 months ago

 nop is not working Empleados.jrxml (The system cannot find the file specified)

 

I have my empleados.jrxml file in the same directory with my jsp page 

gerson2002's picture
Joined: Nov 15 2011 - 12:29am
Last seen: 11 years 10 months ago

plz give full flow

prabhakaranv1991 - 9 years 10 months ago
Feedback
randomness