Use eclipse to display the Crystal Report on JSP (2) Background code example

Source: Internet
Author: User

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.

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.