Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

file .jasper and jsp  RSS feed

jaime cruz
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am attempt to print a report.jasper from jsp file but it is print a blank page
below is the code. can anybody help me? Please

<%//@ page errorPage="error.jsp" %>
<%//@ page import="datasource.*" %>
<%@ page import="dori.jasper.engine.*" %>
<%@ page import="java.util.*" %>
<%@ page import="*" %>
<%@ page import="*"%>
<%@ page import="dori.jasper.engine.export.*"%>
<%@ page import="dori.jasper.engine.util.*"%>
<%@ page import="dori.jasper.view.*"%>
<%@ page import="java.sql.*"%>
<%@ include file="coneccion.jsp"

Driver d = (Driver)Class.forName(DBDriver).newInstance();
Connection conn = null;
conn = DriverManager.getConnection(strConn,DBusername,DBpassword);
//String driver = "oracle.jdbc.driver.OracleDriver";
//String connectString = "jdbc racle:thin:@dbserver:1521 rcl";
//String user = "hpdemo";String password = "hpdemo";
//Connection conn = DriverManager.getConnection(connectString, user, password);
File reportFile = new File(application.getRealPath("/reporte10.jasper"));
String path = reportFile.getAbsolutePath(); //tried getAbsolutePath()
//System.out.println("Absolute Path = " + reportFile.getAbsolutePath());
Map parameters = new HashMap();
parameters.put("myparam",new Integer(2));
parameters.put("ReportTitle", "Address Report");
parameters.put("BaseDir", reportFile.getParentFile());
JasperPrint jasperPrint = JasperManager.fillReport ( path,parameters, conn);
byte[] bytes = JasperRunManager.runReportToPdf(reportFile.getPath(), parameters, conn);
JRPdfExporter exporter = new JRPdfExporter();
ByteArrayOutputStream pdfReport = new ByteArrayOutputStream();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, pdfReport);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE, application.getRealPath("/Centros2/reporte10.jasper"));
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, "reporte10.pdf");
bytes = pdfReport.toByteArray();
OutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
}catch(Exception e)
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the pdf page is saved in your web directory
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!