Use eclipse to display the Crystal Report on JSP (4) pojo filling report

Source: Internet
Author: User

In eclipse, how does one insert pojo into the crystal report? This is what we need to do in the fourth article.

First, we should create an object class.

Here I use orderitems. Java as an example, code

Package com. jrc. beans;

Public class orderitems ...{
Public int ID; // the ID of the corresponding database table
Public int quantity; // number of products, which are not available in database tables
Public orderitems (int id, int quantity )...{
Super ();
This. ID = ID;
This. Quantity = quantity;
}
/***//**
* @ Return ID
*/
Public int GETID ()...{
Return ID;
}
/***//**
* @ Param ID: ID to be set
*/
Public void setid (int id )...{
This. ID = ID;
}
/***//**
* @ Return quantity
*/
Public int getquantity ()...{
Return quantity;
}
/***//**
* @ Param quantity the quantity to be set
*/
Public void setquantity (INT quantity )...{
This. Quantity = quantity;
}
}

 

If you have not created a report, create a report, such as report. Rpt, and open the report.

In the project resource manager, click orderitems. + (the image cannot be sent) in front of Java. You can see "Green Point orderitems". Right-click "Crystal Reports-" and add it to the current crystal report. Alternatively, you can directly pull "Green Point orderitems" to the report.

In this way, orderitems will be added to the report data and a database table will be added to the report data, such as products (product_id, product_name, product_price ,....,)

If there is no problem, report. the data in the RPT report contains the orderitems table and the products table, and left-click the ID of the orderitems table to pull it to the products_id of the Products table. You can find that there is a line between them.

In this way, orderitems. ID is associated with products. products_id. The default Line property in the middle is equal to or you can change it to another one.

Right-click report. rpt-Crystal Reports-create viewer JSP-select viewer API code insert-select use pojo to fill the report and connect to the Crystal Report page viewer-OK

A new Report-viewer.jsp page is coming out. However, it is useless now. You need to change a bit of stuff in it.

Note: The jrchelpersample class is used in the Report-viewer.jsp. This is a very good tool class in the CR project created in (1). Copy it to your project if it's okay, this class is used in many places. This class is included in the package com. businessobjects. samples.

 

String reportname = ""; // enter your report name

 

 

List dataset = new arraylist ();
Dataset. Add (New orderitems ());
Dataset. Add (New orderitems ());
Dataset. Add (New orderitems ());
Dataset. Add (New orderitems ());
Dataset. Add (New orderitems ());

You can use the orderitems constructor to add a dataset. You can use many methods to add a dataset. You only need to add an exact and effective orderitems object.

Remove /**/

Start Tomcat and run the Report-viewer.jsp.

 

Related Article

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.