Let's take a look at the problems already elaborated in the previous document: 1. How to connect to the database?
2. How to define variables, parameters, and fields?
3. How to define fonts and how to use custom fonts (such as black body, body or comparative artized sub)?
Below we will explain the two problems under the rest, and I have added two places that should be elaborated by the previous document before the start of the previous document. The first is that I forgot to describe how Ireport compiles XML files into a Jasper file, which is very simple, click "Compile" button
That is, in fact, you click two "run"
"Buttons is the default operation is to compile the XML file. The second is how to set the output format of IREPORT, we have said that IREPORT can be output in many formats, such as PDF, HTML, XML, XLS , CVS, etc., how do we set what way to output? We can see that IREPORT's default output format is PDF, as shown in the figure:
PDF Preview Default Output HTML Preview In the format of the page, it will not be said. If you try it, J but only set the output format, there is no setup, and there is a required setting is For each set, select the Environment, for example, if you choose to output with a PDF, you need to specify the path to the Acrobat Reader, such as the figure selection menu Tools / Options, will pop up the following property page:
There is still something that I want to explain here. The settings of External Editor are the editor of the EXTERNAL EDITOR. Here I usually use UltraEdit to edit, you may like to use other, such as EditPlus, then use common The XML editor is entered here to edit the XML file as you want, edit the XML file into the menu "Edit / Edit XML Source", will pop up your familiar editor to edit the XML file, as shown:
There is also the last point to add, in the previous document, the PDFFontName of the font of the non-Synchron is absolutely path (such as: c: /winnt/fonts/simhei.ttf), in fact, this is wrong , You should pack it in the font in the app, so that the absolute path is the relative path (such as ReportFonts / Simhei.ttf), so there is no loss, huh J J
Ok, do the complement of the upper side, let us follow the previous problems, first list the problem to be solved below: 4. How do I perform SQL scripts to query?
5. How to introduce a good statement into the app?
Let's solve it by one of us a problem.
4. How do I perform SQL scripts to query?
Everyone knows that from the data query must have a query statement, when the specifically inquiry may be more complicated, how does IREPORT make us use their own query statement to output? We have mentioned in the previous one, huh, huh J, I hope you will not forget, there is a reprot query item under the menu view, click, click the following property page:
Click on "Save Query to Report" on the image above, the SQL statement will introduce this query statement to the report. If you check the XML file at this time, you will find the following piece:
The following effects will be obtained:
Oh, I got the effect of our expectations. At this time, you may ask if I want to use the parameters in the SQL statement, then what? In fact, I will immediately say this question. If we want to make a fuzzy query with a name, the parameter passed is Name, then the expected SQL statement may be the following:
Select * from users where name like '% Name%' actually can be easily implemented in iReport, remember that we have said the use of parameters in the previous document, so I don't say much, I only put the final SQL. The statement is written to everyone, I believe that everyone will understand:
Select * from users where name like '% $ p {name}%' is not very simple? J
5. How to introduce a good statement into the app?
In fact, in Question 4, if you want to run a query report with parameters, you will involve problems 5, so I still want to quote the problem of 4 problems here. At this point we have to introduce a JSP page, assume that pdf.jsp, then the following is the PDF.JSP code:
<% @ Page Import = "Dori.jasper.Engine. *"%> <% @ page import = "java.util. *"%> <% @ page import = "java.io. *"%> <% @ Page Import = "java.sql. *"%>
<% File reportfile = new file (Application.getRealPath ("/ Reports / Test.jasper"));
Map parameters = new hashmap (); parameters.put ("name", "p"); connection conn = null // below ignore the database connection process // ... // ...... Byte [] bytes = jasperrunManager.RunreportTopdf reportFile.getPath (), parameters, conn); response.setContentType ( "application / pdf"); response.setContentLength (bytes.length); ServletOutputStream ouputStream = response.getOutputStream (); ouputStream.write (bytes, 0, bytes. Length); OuputStream.flush (); OuputStream.close ();%> There is also a necessary step is to put the jasperreport.jar you download under your application's lib, ok, start your app, run DBF.JSP will see the following effects
How, according to the fuzzy query result is in line with our expectations, I believe that you have already mastered the method of the upper side.
Of course, the examples I have given are the easiest, and the typography of the report is also more casual. I believe a little, beautiful reports can be inactivated, huh, huh J, practice more.
to sum up
This series of documents finally finished writing, always feel a bit random, but I hope to give a little help, there are many places that have some shallow tastes, I hope you don't understand or think that I will leave a message or write. letter. My site: http://plateau.sicool.com Email: Plateau_t@sina.com
PS: I have given JasperReport too little space in this series of documents, not it is not important, although Ireport can do very good for us, but it is still very important to JasperReport, I rarely explain its other Cause I also said in the first document, in fact, JasperReport's supporting document is very rich, you can download it on my site. Thanks again to "Open Source" to give us everything.
JPLATEAU, Saturday, December 27, 2003, is written in Guangzhou