1. cache report source
Cache the report source in session variables so that the report source can be effectively used multiple times. When a report source is not cached, It is very expensive to create a new report source multiple times. In addition, the cache report source allows you to refresh a report that contains or does not contain saved data.
The following example shows how to cache Report Sources in session variables:
String report = "/reports/sample. rpt ";
Reportclientdocument reportclientdoc = new reportclientdocument ();
Reportclientdoc. Open (report, 0 );
Object reportsource = reportclientdoc. getreportsource ();
Session. setattribute ("reportsource", reportsource );
Note:If you want to use the cached report source, do not call the discard method of the viewer or report source before you stop using the report source.
We strongly recommend that you cache the report source to ensure data consistency when viewing the report. If you use a non-cached report source, a new report source is created when you perform any operations in the viewer or report control. Therefore, using an Uncached report source will result in the viewer displaying some pages that contain saved data and other pages that contain real-time data.
2. Only the page of the viewer is available.
If the JSP page only contains the viewer without any other content, you can perform some operations to simplify the report viewing implementation.
Set setownpage
Depending on the View content, the viewer can generate a complete HTML page and set corresponding page properties. Setting setownpage to true enables the viewer to completely process the surrounding HTML content, which brings several benefits. Allowing the viewer to process the surrounding HTML content can reduce the amount of code that needs to be added to the JSP page, and enable the viewer to automatically determine certain settings:
- It allows the viewer to select which page start and end tags are used based on the devices used to view the page.
For example, for a Web browser, the viewer will writeStart to mark, and for mobile devices, write<wml>
Start tag.
Note:Java reporting component does not support generating reports for display on mobile devices.
- It correctly sets the content type and character set information for the page. This ensures that the page containing international characters is correctly displayed.
- It automatically enables export and print button support in the viewer.
If setownpage is set to false, You need to manually set the HTML Tag and content -T Ype and charset commands. In addition, when setownpage is set to false, the print and export functions are disabled.
Use the processhttprequest Method When setownpage is set to true, you must use the processhttprequest method instead of the gethtmlcontent method to display the report. The processhttprequest method must be used because the effect of using gethtmlcontent is the same as that when setownpage is set to false, which does not have any advantages when setownpage is set to true.
3. Use the setownform Method If the JSP page does not contain any controls that require sending back, set the setownform method to true. In this way, the viewer can automatically process view status information. View status is used to cache information about the current status of a report on the client. If there are other controls on the page, you must ensure that setownform is set to false and view status information is processed manually.
The following example shows how to manually set view status information:
Viewer. setownform (false );
Viewer. setviewstate (string) Session. getattribute ("viewstate "));
Viewer. processhttprequest (request, response, getservletcontext (), pagecontext. getout ());
Session. setattribute ("viewstate", viewer. getviewstate ());
Note:Setownform must be set to true to make the parameter prompt take effect.
4. Specify the correct Character Set To send characters from a JSP file to a Web browser, you must use the correct encoding. Always specify the correct content type and character set for all JSP pages.
If the JSP page returns the content to the standard HTML browser, make sure that the correct character set is defined:
<% @ Page contenttype = "text/html; charset = UTF -8 "%>
The contenttype and charset commands let the browser know the encoding method of the returned HTML page. UTF -8 Is the character set required by the viewer.
5. Example code of crystalimagecleaner To regularly Delete temporary files used by the viewer, you must use the crystalimagecleaner object. Adding the correctly configured crystalimagecleaner object to the JSP page using the viewer can help improve the performance of Web applications.
Note:To ensure that the crystalimagecleaner object is available, the following lines of code must exist in the JSP page.
<% @ Page import = "com. crystaldecisions. Report. Web. Viewer. crystalimagecleaner" %>
Example 1 In this example, create a crystalimagecleaner object that scans image files once every minute, but only deletes files that already exist for at least two minutes. Since the best values of these settings are highly dependent on the use of the viewer and the design features of the application, you must adjust these settings correctly to ensure optimal performance for your application.
<%!
Public void jspinit (){
Crystalimagecleaner. Start (getservletcontext (), 60000,120 00 );
}
%>
Example 2 In this example, the crystalimagecleaner object is stopped after the JSP page is deleted from the service.
<%!
Public void jspdestroy (){
Crystalimagecleaner. Stop (getservletcontext ());
}
%>