The article will involve three aspects:
Part 1: Use the IREPORT to make a detailed process (in the Windows environment)
Part II: Develop fat client report applications using JasperReport as a report control
Part III: Develop Web Report Applications using JasperReport as a report control
1 Overview
How to implement a WEB report has a lot of options, custom CSS HTML or XSLT XML or other controls, especially controls that support charts, such as JFreechart. As a way of implementation of Web reports, it is recommended that you use JasperReport as a report control, first, two sections have introduced the production report and develop fat client report applications. In fact, there are many articles to refer to the third part of the third part. The content is not only this article I wrote.
2, data connection is established
Refer to http://blog.9cbs.net/jemlee2002/Archive/2004/09/28/JJem.aspx, here is detailed to introduce the connection process of the database.
3, copy the necessary JAR file to the web-INF / lib directory for web applications
Each web application will have a web-inf directory, but lib is not necessarily, if you don't create it, there are 3 JAR library files required by this article:
JasperReports-0.5.3.jar: The API required when executing JasperReports
ITextasian.jar: Asian character set support
ITEXT-1.02B.jar: Other character set support
If your report is full English or does not need to support the Asian character set, then ITextasian.jar can not.
4. Create a repotrs directory and import .jasper files
Create a repotrs directory in the root directory in the web application, in fact, this is a suggestion, there is no need to do this, you can create N directories or hierarchical directories based on your business needs.
Copy the .jasper file to the repotrs directory, such as the businessrpt.jasper file in the example.
5, example program
Test.jsp file content:
<% @ Page session = "false"%>
<% @ page import = "DORI.JASPER.EENGINE. *"%>
<% @ Page Import = "javax.naming. *"%>
<% @ Page Import = "java.sql. *"%>
<% @ Page Import = "javax.sql. *"%>
<% @ Page Import = "java.util. *"%>
<% @ Page Import = "java.io. *"%>
<%
DataSource DS = NULL;
Try {
InitialContext CTX = New InitialContext ();
DS = (DataSource) CTX.lookup ("Java: Comp / Env / JDBC / MySQL");
Connection conn = ds.getConnection (); // Load JASPER file
File business_rpt = new file (Application.getRealPath ("/ Reports / Businessrpt.jasper"));
// Configure parameters, you can refer to the second part: use JasperReport as a report control to develop fat client report applications "
// http://blog.9cbs.net/jemleE2002/Archive/2004/108/jjem3.aspx
// Projectname is the name of Ireport's variable $ p {projectname},
/ / Refer to 5.6 of the first part and use parameters
// PRONAME is the value obtained from the interface.
Map parameters = new hashmap ();
Parameters.put ("ProjectName", Proname;
// JasperRunManager is an output control management class, which refers to some content
Jasperrunmanager.RunReportTohtmlfile (Business_rpt.getPath (), Parameters, Conn;
// If the creation report is successful, turn to the report, in fact, the report can be set in the frame, which enables more meaningful report format.
Response.sendRedirect ("/ reports / businessrpt.html");
} catch (exception ex) {
Out.print ("Exception Exceptions, information is:" ex.getMessage ());
EX.PrintStackTrace ();
}
%>
hEAD>
body>
html>
6, about Jasperrunmanager
JasperRunManager has a lot of static methods, controlled the format, such as PDF or HTML, is recommended to browse some methods of JasperRunManager, which helps the development report output.
7, output content
The output format in the example is in an HTML file format, so the web server can directly explain and display, the effect is good.
8, summary
Finally, I will finish the content of the 3 parts. I can take a break here, just like a master: "Rest, rest ...".