tags: Java
, JasperReports
, J2EE
posted: Friday, April 8th, 2005
The most recent project I have been working on involved creating a large number of reports for the company’s extranet/intranet. In the past, I have usually done reports using some form of JSP and JDBC. But in this case, there is a large number of reports to be developed, and so I was tasked with researching some of the open source solutions for reporting, in hopes we could find a solution that would allow us to get the reports done faster, and be provided to the user with more functionality, and with less custom code.
In the end we compared Crystal reports with JasperReports, and JasperReports was picked. JasperReports is not only free, but also is proven in the Java world, and has a lot of users. It is customizable, since its Java and open source, and has support for using Collections or Lists of Business Objects, such as those populated via Hibernate.
Once JasperReports was chosen, I tested several GUI’s to help build the reports instead of editing them strictly in their native XML. JasperAssistant was found to be the best of all of them, and integrates seamlessly with Eclipse. If you are an Eclipse fan as I am, then you’ll love using JasperAssistant. It even allows you to preview the report against your database right in Eclipse.
Next, I looked into OpenReports. OpenReports is a front end for JasperReports. It was written in WebWork, and provides a lot of functionality that you would have to write yourself to get the reports running on the web. It comes with basic security (users, passwords, and reporting groups). You can assign which users can access which groups, and which reports are in which groups. You can also add parameters, and then assign them to a report. You create the JasperReport in JasperAssistant (or with any other tool, including a text editor if you want to do the XML by hand), and then compile it (which JasperAssistant does for you). Then when you add a new report to OpenReports, you select which JasperReport file to use, select your datasource, assign your parameters and the report is ready to be used on the web.
OpenReports allows the user to export the report as a PDF, HTML, CSV, XLS, or PNG. This is all done for you without any additional work. As for parameters, there is some good functionality built in. When you add a Date parameter to your report, it automatically brings up a calendar for the user to select the date with. Also, you can add a query parameter which runs an sql that you have specified, and populates a drop down select box with the results. Parameters can be marked as required or optional, can be several different data types, and can be told to come in in any order needed. There are other parameter options as well. It also allows the user to schedule a report and have it emailed to a user.
I have made some improvements to OpenReports, including the Collection/List functionality to use Business Objects which JasperReports supports, but OpenReports currently doesn’t. At some point I’ll pass that code on to the original developers.
In the end, with JasperReports and OpenReports, the only thing you have to worry about is creating the SQL to get the data. After that, it takes little work to provide a nice looking report in multiple formats on a web site.
Comments (275)
Leave a Comment
Pages: « 28 … 24 23 22 21 20 [19] 18 17 16 15 14 … 1 » Show All
My jasper report have a sub report. I deployed my Jasperreport on the jasperserver and when I run it, “parameter DATABASE_TIMEZONE does not exist” error is coming. Kindly give a solution to this..
Thanks in Advance…
SIVA
I have to change dynamically the number of columns in report.The problem is like the following.
There is a list box in jsp page,that contains the column names.User selects columns in list box that are printed in report.Therefore,i must create report dynamically.How can i organize this report using jasperreport?
Hi Brian;
I have used jasper reports in the past with JBOSS with no problems, however, when trying to generate a simple report in websphere, I get the following error:
TRAS0014I: The following exception was logged java.lang.reflect.InvocationTargetException: java.lang.NoSuchMethodError: com.lowagie.text.pdf.PdfContentByte: method transform(Ljava/awt/geom/AffineTransform;)V not found
try{
JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile);
JRCsvDataSource ds = new JRCsvDataSource(new FileReader(dataSourceFile1));
ds.setColumnNames(getFAISColumns());
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds);
int read = 0;
System.err.println(”TOTAL PAGES = “+jasperPrint.getPages().size());
byte [] bytes = new byte [1024];
ByteArrayInputStream is = new ByteArrayInputStream(JasperExportManager.exportReportToPdf(jasperPrint));
response.setContentType(”application/pdf”);
response.setHeader(”Content-disposition”, “inline; filename=report.pdf”);
outputStream = response.getOutputStream();
while((read = is.read(bytes)) != -1){
outputStream.write(bytes, 0, read);
}
outputStream.flush();
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
Any ideas?
Hi Brian;
I have used jasper reports before in JBOSS and had no problems, however, when trying to generate a simple report in websphere, I get the following error:
TRAS0014I: The following exception was logged java.lang.reflect.InvocationTargetException: java.lang.NoSuchMethodError: com.lowagie.text.pdf.PdfContentByte: method transform(Ljava/awt/geom/AffineTransform;)V not found
I have chopped and changed the code and the report six ways from Sunday, yet the same error occures.
Here is the code:
try{
JasperReport jasperReport = (JasperReport)JRLoader.loadObject(reportFile);
JRCsvDataSource ds = new JRCsvDataSource(new FileReader(dataSourceFile1));
ds.setColumnNames(getFAISColumns());
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, ds);
int read = 0;
System.err.println(”TOTAL PAGES = “+jasperPrint.getPages().size());
byte [] bytes = new byte [1024];
ByteArrayInputStream is = new ByteArrayInputStream(JasperExportManager.exportReportToPdf(jasperPrint));
response.setContentType(”application/pdf”);
response.setHeader(”Content-disposition”, “inline; filename=report.pdf”);
outputStream = response.getOutputStream();
while((read = is.read(bytes)) != -1){
outputStream.write(bytes, 0, read);
}
outputStream.flush();
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
hi
I am Gangadhar. I am working with jasper report. I made xml file which is stored in E:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\Torque\WEB-INF\classes folder where Torque is my folder name. Every thing of java code is working fine but jasper compileManager doesn’t find xml file. please guide me where to store xml file & what changes are required to work program correctly. I am also forwarding my java code. please guide me.
import java.util.*;
import net.sf.jasperreports.engine.*;
import net.sf.jasperreports.view.*;
public class JasperReportIntro
{
public static void main(String[] args)
{
String reportSource = “Torque/Simple.xml”;
String reportDest = “Torque/Simple.html”;
try
{
Map param = new HashMap();
JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,param, new JREmptyDataSource());
JasperExportManager.exportReportToHtmlFile(jasperPrint, reportDest);
JasperViewer.viewReport(jasperPrint);
}
catch (JRException e)
{
e.printStackTrace();
}
}
}
I also need to make a report with a pdf as background, so i can write uppon it. Anyone knows how this is possible ?
Thanks in advance
Nuno Silva
Hi,
I am using Jasper Reports for our automated clearing & settlement system which is developed using java struts framework and run on tomcat5.5. currently we use some reports designed on jsp. But now we have to develop a lot of reports and i already made some reports using jasper report (iRepor). When i generate a Jasper Report, it opens up on the server (in Jasper Viewer) not on the client and after generating the report the tomcat goes to be hang.
Please tell me what I need to do to open up a Jasper Report on the client.
Right now it is opening up in the server, I need to open it on the client.
Hi,
I need generate dynamic columns using JasperReports. In this moment i’m using iReport for create the templates, but this are statics templates, and i need dynamic columns , dynamic xml source that can modified the templates dynamically
if Someone has a solution please, help me.
Thanks!!
Hi All,
I am using jasper for reporting in my application. The application “war” file is deployed in WebSphere, And it is failing during report initialization.
Can any body plz tell me, why I am getting this error. Probably what are the suspected cause behind this.
Thanks in advance,
Sanjib
[1/16/07 17:53:14:562 IST] 5639e40e WebGroup E SRVE0020E: [Servlet Error]-[reports]: Failed to load servlet: net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. java.sql.Connection cannot be resolved to a type value = (java.sql.Connection)(((java.sql.Connection)parameter_REPORT_CONNECTION.getValue()));
2. java.sql.Connection cannot be resolved to a type
value = (java.sql.Connection)(((java.sql.Connection)parameter_REPORT_CONNECTION.getValue()));
3. java.sql.Connection cannot be resolved to a type
value = (java.sql.Connection)(((java.sql.Connection)parameter_REPORT_CONNECTION.getValue()));
4. java.sql.Connection cannot be resolved to a type
*
*
—————->
18 errors
Pages: « 28 … 24 23 22 21 20 [19] 18 17 16 15 14 … 1 » Show All
RSS feed for comments on this post. TrackBack
Hi Brian,
I am trying to call a DB2 stroed procedure from Jasper Reports.
I can successfully call a stored procedure which only requires input parameters but can’t work out how to call one which requires both input and output parameters.
Any ideas?