The configuration in (1) remains unchanged. The previous article used the crviewer label to display the Crystal Report in JSP.
This article teaches you how to write your own code to enjoy the Crystal Report
Report_source.jsp
<% @ Page contenttype = "text/html" %> <% @ page pageencoding = "UTF-8" %> <% // crystal Java reporting component (JRC) imports. %> <% -- jrcerom. jar -- %> <% @ page import = "com. crystaldecisions. reports. SDK. * "%> <% -- rascore. jar -- %> <% @ page import = "com. crystaldecisions. SDK. occa. report. lib. * "%> <% // final string report_name =" view_report.rpt "; %> <% Try {// open the report reportclientdocument reportclientdoc = new reportclientdocument (); reportclientdoc. open (report_name, 0); // put the report source into the session and pass it to the session on the Report display page. setattribute ("reportsource", reportclientdoc. getreportsource (); // go to the report display page to response. sendredirect ("crystalreportviewer. JSP ");} catch (reportsdkexception ex) {out. println (Ex);} catch (exception ex) {out. println (Ex) ;}%>
The above code can be encapsulated in JavaBean.
Reportclientdoc. getdatabasecontroller (). Logon (username, password );
Set the database Login User. If the user who browses this report needs to set different permissions, you need to set the preceding permissions.
Crystalreportviewer. jsp
<% @ Page contenttype = "text/html" %> <% @ page pageencoding = "UTF-8" %> <% // crystal report viewer imports. %> <% -- webreporting. jar -- %> <% @ page import = "com. crystaldecisions. report. web. viewer. * "%> <% -- rascore. jar -- %> <% @ page import = "com. crystaldecisions. reports. SDK. * "%> <% // create a viewer object instance and set crystalreportviewer viewer = new crystalreportviewer (); viewer. setownpage (true); viewer. setownform (true); viewer. setprintmode (crprintmode. activeX); // obtain the report source object reportsource = session from the session. getattribute ("reportsource"); viewer. setreportsource (reportsource); // display the crystal report viewer. processhttprequest (request, response, this. getservletconfig (). getservletcontext (), null); // release the viewer object. dispose (); viewer = NULL; %>
Method 2: directly use a page
Crystalreportviewer. jsp
<% @ Page contenttype = "text/html" %> <% @ page pageencoding = "UTF-8" %> <% // crystal Java reporting component (JRC) imports. %> <% -- jrcerom. jar -- %> <% @ page import = "com. crystaldecisions. reports. SDK. * "%> <% -- rascore. jar -- %> <% @ page import = "com. crystaldecisions. SDK. occa. report. lib. * "%> <% -- webreporting. jar -- %> <% @ page import = "com. crystaldecisions. report. web. viewer. * "%> <% // final string report_name =" view_report.rpt "; %> <% Try {// open the report reportclientdocument reportclientdoc = new reportclientdocument (); reportclientdoc. open (report_name, 0); // put the report source into the session and pass it to the report display page. // session. setattribute ("reportsource", reportclientdoc. getreportsource (); // create a viewer object instance and set crystalreportviewer viewer = new crystalreportviewer (); viewer. setownpage (true); viewer. setownform (true); viewer. setprintmode (crprintmode. activeX); // obtain the report source from the session // object reportsource = session. getattribute ("reportsource"); // viewer. setreportsource (reportsource); viewer. setreportsource (reportclientdoc. getreportsource (); // display the crystal report viewer. processhttprequest (request, response, this. getservletconfig (). getservletcontext (), null); // release the viewer object. dispose (); viewer = NULL; // go to the report display page // response. sendredirect ("crystalreportviewer. JSP ");} catch (reportsdkexception ex) {out. println (Ex);} catch (exception ex) {out. println (Ex) ;}%>
I personally feel that the first method is good. The report source is separated from the display, which is secure and easy to reuse.