Several key aspects of jasperreport + ireport report Creation

Source: Internet
Author: User

I made some reports some time ago. I wanted to write a blog to summarize them and give some inspiration to my new friends. However, I am a lazy person and have never been able to write it. Yesterday, I made another report. But after a day, I realized what was going on. I 'd like to summarize it. No more similar mistakes will be made in the future!

Many documents have been written about configuring and installing jasperreport and ireport. I won't say much about it. First, let's talk about some common problems. These are the first things we should pay attention:
1. The reports made in ireport are not displayed during preview. In my experience, most of them do not have a font set, or they lack the Asian Language Pack itextasian. jar.
2. If only information such as net. SF. jasperreports. Engine. jasperprint is displayed on the page. Most reports have errors. In ireport, I want to check whether the report parameter is passed or whether there is a problem with the subreport. I was confused about this problem for a whole day and solved it only after work.

3. subreport path settings
I have been troubled by some problems for many days and cannot be relieved. Later, I accidentally fixed it. Despite the hard work, I am very pleased! If the project published to the server appears "cocould not load object: subreportname. Jasper" in the call report ". The subreport cannot be found. But we usually compile it in ireport. And runs normally. Why can't I find it when I port my server to another platform. I have no idea. I just learned the solution:
(1) In ireport, set the missing value of the parameter "subreport_dir" to ""
(2) define the path of the report file in the project in a Java program, for example:
String reportpath = servletcontext. getrealpath ("/WEB-INF/classes/Report") + file. Separator;
(3) Pass the report path "reportpath" to Jasper
Map parameters = new hashmap ();
Parameters. Put ("ID", ID); // you can specify parameters for a report.
Parameters. Put ("subreport_dir", reportpath); // you can specify a path for a subreport.
If a subreport exists in the subreport table. It is also easy to handle. The Java program does not need to be modified. The parameter is required for the sub-table in ireprot.
In fact, jasperreport is a bit mentally retarded. Why not set the report to be in the same path as the primary table by default, because most applications do. In addition, it does not indicate that the sub-table needs to be specially set. The strange thing is that there is no "subreport_dir" parameter in the root of the example !! I really don't understand! If anyone knows the clues, please let me know. Let me make it clear again ......
4. How to Use scriptlet

5. How to Use the Java Data Source

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.