JasperReport is http://www.sourceforge.net's excellent open source report tool, its powerful features and free features have been accepted and praised, and the latest version is JasperReport0.6.1. The download address is https://sourceforge.net/projects/jasperreports/. Ireport is an IDE development tool for JasperReport, making JasperReport more easy, and its latest version is Ireport0.4.0 support to JasperReport0.6.1, and JasperReport is also constantly updated. The download address is https://sourceforge.net/projects/ireport/. About the use of these two tools to develop web reports, there are already a few good materials: JasperReport and Ireport configuration and use .pdf (this document can be used to get started with these two tools) ThejasperReportsultimateGuide.1.0.pdf (This is a charged document, telling the knowledge of JasperReport generated, if you plan to use JasperReport this report tool, you need to see this English information) http://www.javaresearch. ORG / Forum / Thread.j ... 16 & thread = 14374 (this is another introduction guide I wrote in the forum)
First run
The first time is always more painful, using this report tool, the following is the problem that I have summed up in some operations. My summary is based on Ireport0.4.0 JasperReport0.6.1). As for the combination of the two, I still feel relatively smooth. After downloading Ireport-0.4.0.zip from SouceForge, pay attention to it, pay attention to it, copy your JDK's Tools.jar to the lib directory after you decompressed, the Chinese PDF report also needs to copy itextasian.jar Under LIB, if you use Oracle's database, then you need to copy class12.jar is also the Oracle's JDBC package to lib, other databases. It's ready to do it, run Ireport.bat. If the UI interface is read, IREPORT has successfully run.
If the DOS interface passes, it means that there is no success. Follow the steps below: Determine the system installation with JDK, and the system environment settings, there is a bin directory in the path, and there is a java_home parameter, the following is the configuration of several of my parameters for reference: 1 Java_Home D: /Jbuilder9/jdk1.42 path d: /jbuilder9/jdk1.4/bin; d: / install / ant161 / bin3 classpath d: / ireport042 / fonts; E: / project / ESS4 ANT_HOME D : / Install / Ant161 (Description of the above parameter settings: IREPORT0.4.0 requires JDK1.4 or above, so pay attention to Oracle9 to automatically set the Java environment to Oracle's own JDK1.3.1, which will not be able to run IREPORT Ant_home and the ANT settings are examples of JasperReport in the ANT, these examples In the DEMO / SAMPLES directory after JasperReport, such as entering the DOS / Samples / Jasper directory, enter the command ANT View you can see this example report. ClassPath D: / Ireport042 / fonts; settings are to make sure that some external fonts can be selected when font settings in Ireport, such as let PDF display black body, then simhei.ttf under Windows Under D: / Ireport042 / FONTS, set the following in Ireport: pdffontname is an external font, TrueTypefont is simhei.ttf, encoded as unicode with horizontal Writing, so you can use the black body E: / Project / E: / Project / E: / Project / E: / Project / E: / Project / E: / Project / E: / Project / E: / Project / E: / Project / E: / Project / E: / Project / E: / WebApps / Web-INF / CLASSES, this is setting in ClassPath, which is to make some data in the report to be specially processed, can be used in the project. These settings are completed, running Ireport.bat in the IReport directory in the DOS environment. The benefits of the DOS environment are if the Ireport runs failed to see the cause of the failure, and then aimed to solve. After running, it is a discipline and slowly understands the familiar process until you can make a decent statement. this. The process can refer to Http://www.javaresearch.org/forum/thread.j mentioned above.. .16 & three = 14374
Frequently asked questions
When you do a statement, you will encounter a lot of questions. The key is that we need to analyze an error prompt. Based on finding a solution, if you put the report to your work, such as run the results prompt java.io.filenotFoundException, then you need Determine your report compiled file in the corresponding directory; for example, Noclassdeffounderror, then you have to see which package is not placed under your project. It is important to emphasize: Look at the example of JasperReport comes, understand those examples, at least imitate, you can make the report you want.
My report FAQ
1. Java.io.FilenotFoundExceptionJasperReport Self-contained webapp example, the method for targeting .jasper report template file is: file reportfile = new file (Application.getRealPath ("/ reports / webappreport.jasper)); this time If your web server is Tomcat, the file in WAbApp is placed in the root directory. Then the actual location of this report is: d: /tomcat41/webappst.jasper, however, when you use a child report, the situation Different, first there is no Application object in the sub-report so you can't use new file ("/ reports / webappreport.jasper") method to locate the sub-report. JasperReport supports three ways to locate files, and see JasperReportutiMateGuide.pdf here, if you use string type to associate sub-reports, and string's value is subreport.jasper, then JasperReport will go to D: / Tomcat41 / WebApps / root / WEB-INF / CLASSES directory finds if there is a Subreport.jasper this file knows this to take a variety of ways ========================== ===================== JasperReport learning must-have manual This is a little experience I learn JasperReport, welcome everyone to correct, enlighten, I am just a brick role, Everyone will then throw jade, I hope that I can really be tired into a must-have manual, huh, huh.
Suppose you have a certain understanding of JasperReport (at least a probably developing process), here you don't have to explain the benefits of JASPERREPORT, design, expression definitions, etc. Some things in JasperReport bring your documents.
Maybe because I am a java newbie, I have a lot of problems, only some of them, and attach my solution: l JSP can't generate PDF issues
l When generating HTML, JRHTMLEXPORTERPARETER.IMAGES_MAP problem
l Chinese display problem
l Image display implementation (JFreechart)
l My general .jasper generation method
l My project implementation
JSP does not generate a problem with PDF: When running the contracted web (WebApp Directory) example (I use the server is Tomcat), generate PDF with servlet is completely no problem, and JSP mode is galled to getOutputStream () HAS Already Been Called For this response's fault, see the JSP source code discovery and servlet is almost.
Problem: Tomcat first executes the Java code starting with the .jsp file, then prepare the session, OUT and other variables. The code of the output PDF appears in the <% ...%> segment started by .jsp file, this httpserverletresponse's getOutputStream () method has been called. This method defines this method in the JSP specification can only be called once, so it will inevitably be wrong when Tomcat prepares the OUT variable. So Tomcat-based servers are wrong, such as JBoss, Sun ONE AppServer
Workaround: Very simple, define the output non-text content according to the JSP / Servlet specification, such as pictures, sound, etc. should use servlet instead of JSP. The output stream in the servlet is completely turned on / off by the application.
Although it seems that this is not a solution, I checked a lot of places, and I didn't find a better statement, so everyone is JasperReport or servlet.
When generating HTML, JRHTMLEXPORTERPARETER.IMAGES_MAP problem is not a problem, but I am a bit confused at the time, I will come out and say it.
I don't know if you haven't read it, you have the following paragraphs each time you generate HTML:
Map imagesmap = new hashmap ();
Session.SetaTRibute ("Images_map", ImageSmap;
Exporter.SetParameter (JrexporterParameter.jasper_Print, Jasperprint);
Exporter.SetParameter (JrexporterParameter.output_Writer, Out);
Exporter.SetParameter (JRHTMLEXPORTERPARETER.IMAGES_MAP, IMAGESMAP);
Exporter.SetParameter (JRHTMLEXPORTERPARETER.IMAGES_URI, IMAGE.JSP? Image = ");
especially:
Exporter.SetParameter (JrexporterParameter.output_Writer, Out);
Exporter.SetParameter (JRHTMLEXPORTERPARETER.IMAGES_MAP, IMAGESMAP);
Exporter.SetParameter (JRHTMLEXPORTERPARETER.IMAGES_URI, IMAGE.JSP? Image = ");
These words, I feel inexplicable.
Initially guess is to show the picture, can you do it?
And there are a lot of source code for the generated HTML page.
What kind of pictures are it in PX?
View Javadoc, written too simple, not explained at all. So, see the source code:
His.Imagesmap = (map) this.Parameters.Get (JRHTMLEXPORTERPARETER.IMAGES_MAP);
IF (this.imagesmap == null)
{
THIS.IMAGESMAP = New hashMap ();
}
..........
THISLOADIMAGESMAP = new hashmap ();
Byte [] PXBytes = JRIMAGELOADER.LOADIMAGEDATAFROMLOCATION ("DORI / JASPER / ENGINE / IMAGES / PIUR.GIF"); this.loadedImagesMap.PUT (PXBytes, "PX");
THIS.IMAGESMAP.PUT ("PX", PXBYTES);
Haha, the original shape is revealed, the original PX is DORI / JASPER / ENGINE / IMAGES / PIXEL.GIF (a small boss), but it has a great role in the beautiful view of the webpage, do not believe in the wrong image (JSP, servlet) path Look (this is also a place where it is wrong).
Problem Description of Chinese Display: The generated HTML or PDF Chinese is displayed as garbled or not displayed.
Solution (HTML):
If you only ask for generating HTML (may not be such a simple customer), it is good if it is jsp: <% @ page contenttype = "text / html; charset = GB2312"%>
If it is servlet: response.setContentType ("text / html; charset = GB2312");
Haha, I'm big, I predict the Chinese solution of PDF, please call the toll consultation telephone 110.
Solution (PDF):
Let's put down the bricks on your hand. I said yet, just don't know if this is a correct or better solution, please give more points.
CHARSET = GB2312 (it is a genius of a stupid) because there is no place when generating PDF.
We have a three steps.
1. Since JasperReport generates PDF using IText, we need IText Asian language packs.
Http://itext.sourceforge.net/downloads/itextasian.jar.
Place him in the LIB.
2. In JasperReport's design XML, you can define a Chinese font:
Where pdffontname = "stsong-light" pdfencoding = "unigb-ucs2-h" is the font defined in the ITextasian.jar package.
3. Chinese characters use UTF-8 encoding
Function, so she (please allow me to use "her", who makes me a bachelor programmer, 嘿嘿) CHART is generated by other tools, and then as Variable or Parameter passed. In this way, we can make her as much as you want to show any bufferedimage, hey, he is a JFreechart generated or static image.
I am more preferred to define as parameter, because you can get Chart data in the same program that generate JRDataSource, exempt from database operations in the scriptlet, or if it is a simple report, it is saved.
TartDioEngnget.javariter, OUT;
My general .jasper generation method JasperReport comes with Ant, but each sample has different build.xml and .class, can there be a unified component program? Ireport can, but he will write all the properties each time, look unclean, clear, so I modified a paradigm build.xm. and .class to build my JasperReport. Interested in the same way can take a look. 1. Definition in building.xml
Dynamic delivery file name
2. Replace all
3. Modify the program, pass JREMPTYDATASOURCE to each time.
Each time build, just add the parameters on the basis of the previous basis:
-DFILENAME = ******
Such as: ant compile -dfilename = "MyDemo"
The implementation of my project is just a simple package, which may not apply to other systems. If necessary, please contact me.
(This time is more rush, etc. have time to make up)