About transferring values to a report:
If you do not use Birt viewer, you can call your report using APIs. The Birt API has APIs for setting parameters.
If you use the Birt viewer, you can directly use the URL or use the Birt tag.
In this article, parameters are passed to the Birt report in jsp url mode, and then used in the Birt SQL statement:
I. Method 1:
1. Add the parameters to be passed in the jsp url:
Http: // localhost: 8080/Birt-Web/frameset? _ Report = test. rptdesign & sample = My + Parameter
2. Add the report parameter sample with the same name to the report, and then add daThe TA set parameter is associated with the report parameter sample, so daThe TA set parameter can obtain the parameters passed from the JSP page and serve as the query condition.
Method 2:
1. Add the parameters to be passed in the jsp url:
Http: // localhost: 8080/Birt-Web/frameset? _ Report = test. rptdesign & sample = My + Parameter
2. Add the report parameter sample with the same name to the report.
3. Click date sets, select the "script" tag in the middle of the vertex, select beforeopen, and write var sample = Params ["sample"]. value;
If (isample = "null "){
This. querytext + = "where 1 = 1 ";
}
Else {
This. querytext + = "where sample =" + sample;
} 4. After this setting, no DA is required. Set DA in Ta set Ta set parameter.Another implementation method:
1. Set several text boxes for passing parameters on the JSP page
JSP code
<SCRIPT type = "text/JavaScript"> function search () {var ST = document. getelementbyid ("St "). value; // start date var ET = document. getelementbyid ("ET "). value; // end date window. location. href = "run? _ Report = reports/new_report.rptdesign & __parameterpage = false & St = "+ st +" & ET = "+ et;} function print () {var ST = document. getelementbyid ("St "). value; // start date var ET = document. getelementbyid ("ET "). value; // end date window. location. href = "frameset? _ Report = reports/new_report.rptdesign & __ parameterpage = false & St = "+ st +" & ET = "+ et ;} </SCRIPT> Note: When you click the query button, use js to specify the URL to be transferred.
(Window. Location. href = "run? _ Report = reports/new_report.rptdesign & __ parameterpage = false & St = "+ st +" & ET = "+ et ;)
(1) Run (only display, no printing, paging, and other functions): similar to the ordinary HTML page, the style needs to be designed in the Report. changing it to frameset has all functions.
(2) parameter: ST (start date), ET (end date)
2. rptdesign File Settings
(1). Report Parameters
Name Data Type display as -- format
St data text box custom: yyyy-mm-dd
Et data text box custom: yyyy-mm-dd
(2). dataset Parameters
Name Data Type direction defalut value linked to report paramter
St Date input N/A st
Et Date input N/A et
(3). dataset SQL (time from? To? )
Select * From tabelname where tbtime betweem? And?
Two problems were found when parameters were passed to BIRT in URL mode.
1. You need to use urldecode for secondary processing, which is troublesome;
2. The parameter length is limited, which is disgusting. There is no way to get a long parameter;
Later, we considered passing the session parameter in the script.
Java code
importPackage(Packages.java.io,Packages.java.util,Packages.java.net); importPackage(Packages.javax.servlet.http); request=reportContext.getHttpServlet(); var session = request.getSession(); status = session.getAttribute("whereClause");
The result shows that the request is always null, because this request is different from the request under javax. In fact, it can be implemented through Java processing, but I am too tired.
After studying N for a long time
Adding an object to the application context for the viewer
Use the appcontext method to transmit data. Finally, the Birt web parameter transfer was successfully processed. The passed content and length are the same as those in Java.
Java code
String contextKey = "whereClause"; request.getSession().setAttribute("AppContextKey", contextKey); request.getSession().setAttribute("AppContextValue", sql);
Used in report
Beforeopen.
How to pass Parameters in Java code to reports? How can I obtain this parameter in a report?
A: PASS Parameters to the report in this way:
Hashmap parammap = new hashmap ();
Parammap. Put ("birtparam1", 1 );
Parammap. Put ("birtparam2", 5 );
Task. setparametervalues (parammap );
Set the report parameter to the same name as the passed parameter.
Bind dataset parameters to report Parameters
"?" In the SQL statement Corresponding dataset Parameters