Jump to content

Example to read jasperreport jsp?


gerson2002

Recommended Posts

 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

                             

 

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

 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>
Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...