Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

file .jasper and jsp

 
jaime cruz
Greenhorn
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="java.io.*" %>
<%@ page import="dori.jasper.engine.data.*"%>
<%@ page import="dori.jasper.engine.export.*"%>
<%@ page import="dori.jasper.engine.util.*"%>
<%@ page import="dori.jasper.view.*"%>
<%@ page import="java.sql.*"%>
<%=application.getRealPath("/reporte10.jasper")%>
<%@ include file="coneccion.jsp"
%>

<%
try
{
Driver d = (Driver)Class.forName(DBDriver).newInstance();
Connection conn = null;
conn = DriverManager.getConnection(strConn,DBusername,DBpassword);
//String driver = "oracle.jdbc.driver.OracleDriver";
//Class.forName(driver);
//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");
exporter.exportReport();
bytes = pdfReport.toByteArray();
response.setContentType("application/pdf");
response.setContentLength(bytes.length);
OutputStream ouputStream = response.getOutputStream();
ouputStream.write(bytes, 0, bytes.length);
ouputStream.flush();
ouputStream.close();
}catch(Exception e)
{e.printStackTrace();
}%>
 
Kithsiri
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the pdf page is saved in your web directory
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic