[Statement] The content part is taken from the Internet. Thank you for sharing it.
Part 1: Environment Configuration
I. installation and configuration of JDK, web server and database
(Here, We will test the environment jdk1.5, resin2.1.7, and sqlserver2k)
Ii. Installation of ireport
Http://ireport.sourceforge.net
Latest Version 1.3.3
The package already containsIText-1.3.1.jarAndJasperreports-1.3.3.jar
Download Chinese support package for reportsItextasian. JarHttp://itextpdf.sourceforge.net (Note: registration required)
Decompress the downloaded ireport to any directory, as shown in figureD:/iReport-1.3.3SetItextasian. JarAddLibDirectory
RunIreport. batOrIreport.exeCan be startedIreport
Part 2: ireport Introduction
Jasperreports can be understood as a compiler or parser. You can use ireport or a text editor to design reports. The encoding format must comply with the XML encoding format defined by jasperreports. DTD labels and attributes. With this XML file, you can define the entire report, describe where to place text boxes, graphics, how to access data, how to calculate column values, and how to display it. How jasperreports works
The XML source file must be compiled to generate a file suffix ". "Jasper" report file, which is provided by jrdatasource to fill the report file. Now with the data added to the Jasper file, you can generate a print report. That is, a datasource + A Jasper file = a print
Ireport is a visual design tool for creating jasperreport XML files. The following is a simple description of its usage:
I. System Option ConfigurationOptions | options, The following configuration points
Ii. Data Source settings:Data | connection/Data Source, Select new, database JDBC connection
Note: first place the JDBC package under the directory LIB; otherwise, the driver of your database cannot be displayed; you can also add the jar package in Options | classpath.
3. Introduction to the main tool bar
Iv. Band details
V. Report Parameters
System Default Variables
$ V {page_number}Indicates the current page number (it can be a page number or a page number, which is set based on the calculated time value of textfield)
$ V {page_count}Number of records on the current page
$ V {groupname_count}Number of records in the current group
$ V {column_number}Column number
$ V {column_count}Number of records in the current column (it is the sequence number of the rows on the current page, and is reset to 1 on the new page)
$ V {report_count}Number of data source records in the current document
6. If the file is output in PDF format, set the element font as follows:
-------------------- Note: There is no time to write. The following content is simplified ------------------------
Part 3: simple example
I. UseArchives | report genie
1. Select the connection/Data Source (the data source) and fill in the REPORT query statement in SQL query.
2. Select the field name to be displayed based on your query statement
3. You can select three grouping fields. Note that if you select grouping fields, the corresponding order by clause should be added to the SQL statement.
4. Select Report Layout
Reference http://ireport.sourceforge.net/swf/Report_Wizard_viewlet_swf.htm
Ii. Report parameter settings
Reference http://ireport.sourceforge.net/swf/Parameters_viewlet_swf.htm
Iii. subreports
Reference http://ireport.sourceforge.net/swf/Subreport_viewlet_swf.htm
(Note: P must be added before the video subreport parameters, and no video is added)
Iv. Grouping reports
Reference http://ireport.sourceforge.net/swf/Groups_viewlet_swf.htm
Note: Click to download all videos
Http://jasperforge.org/sf/docman/do/downloadDocument/projects.ireport/docman.root/doc1021
Part 4: Web Application Examples
Package to be added (available in the ireport directory Lib ):
Commons-beanutils-1.7.jar
Commons-collections-2.1.jar
Commons-digester-1.7.jar
Commons-logging-1.0.2.jar
Itext-1.3.1.jar
Itextasian. Jar
Jasperreports-1.3.3.jar
I. Code for fat clients:
String xmlfilename = system. getproperty ("user. dir") + "// test_report.jrxml ";
String jasperfilename = system. getproperty ("user. dir") + "// test_report.jasper ";
String printfilename = system. getproperty ("user. dir") + "// test_report.jrprint ";
Try {
/* Compile the report file. jrxml to generate the file. Jasper */
Jaspercompilemanager. compilereporttofile (xmlfilename );
/* Set parameters */
Hashmap Params = new hashmap (); // create a parameter table
Params. Put ("yourparamname", ""); // set the parameter value
Connection CNN = getconnection (); // Add the database connection function by yourself.
/* Fill in the report file. Jasper to generate the file. jrprint */
Jasperfillmanager. fillreporttofile (jasperfilename, Params, CNN); // fill the report with data
/* Preview the report file. jrprint */
File sourcefile = new file (printfilename );
Jasperprint = (jasperprint) jrloader. loadobject (sourcefile); // generate report results
Jasperviewer. viewreport (jasperprint); // preview a report
Freeconnection (CNN); // Add a function to release the database connection.
} Catch (jrexception e ){
E. printstacktrace ();
}
Ii. jsp access method
Boolean isok = true; // determines whether the request is successful.
Try {
// Step 1: load the Jasper File
File jasperfilename = new file (request. getrealpath ("/reports/test_report.jasper "));
// Step 2: Set the parameter value
Hashmap Params = new hashmap ();
Params. Put ("yourparamname", ""); // set the parameter value
// Step 3: generate a PDF file using jasperrunmanager
Connectionpool connmgr = connectionpool. getinstance ();
Connection conn = connmgr. getconnection ();
Jasperrunmanager. runreporttopdffile (jasperfilename. getpath (), parameters, Conn );
} Catch (exception ex ){
Isok = false;
}
// You only need to access the/reports/test_reporttables page