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
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> |
plz give full flow