Jump to content
JasperReports Library 7.0 is now available ×

Can't generate .jasper file and exception


Recommended Posts

By: Tuan Le - lesoft

Can't generate .jasper file and exception

2003-10-09 10:53

In my servlet, I have this code below. But, when I run this code, it doesn't generate .jasper file, and it throws an exception at JasperRunManager.runReportToPdf(). Do you know what I'm missing? Thanks!

 

--- Servlet code: within a struts framework ---

 

ServletContext context = this.getServlet().getServletContext();

System.setProperty("jasper.reports.compile.class.path",

context.getRealPath("/WEB-INF/lib/jasperreports-0.5.0.jar") +

System.getProperty("path.separator") +

context.getRealPath("/WEB-INF/classes/"));

System.setProperty("jasper.reports.compile.temp", context.getRealPath("/WEB-INF/reports/"));

 

JasperCompileManager.compileReportToFile(context.getRealPath("/WEB-INF/reports/TestReport.xml"));

File reportFile = new File(context.getRealPath("/WEB-INF/reports/TestReport.jasper"));

 

// Second, create a map of parameters to pass to the report

Map parameters = new HashMap();

parameters.put("ReportTitle", "Focal Review Manager Summary Report");

 

// Third, get a database connection

DAOFactory factory = DAOFactory.getDAOFactory(DAOFactory.SQLSERVER);

IReportingDAO reportingDAO = factory.getReportingDAO();

Connection conn = reportingDAO.getDBConnection();

 

byte[] bytes = null;

bytes = JasperRunManager.runReportToPdf(reportFile.getPath(),

parameters,

conn);

if (bytes != null && bytes.length > 0) {

response.setHeader("Expires", "0");

response.setHeader("Cache-Control",

"must-revalidate, post-check=0, pre-check=0");

response.setHeader("Pragma", "public");

response.setContentType("application/pdf");

response.setContentLength(bytes.length);

ServletOutputStream ouputStream = response.getOutputStream();

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

ouputStream.flush();

ouputStream.close();

}

}

catch (JRException jre) {

System.err.println(jre.getMessage());

}

catch (Exception e) {

System.err.println(e.getMessage());

}

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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...