MrBool
You must be logged in to give feedback. Click here to login
[Close]

You must be logged to download.

Click here to login

[Close]

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

[Close]

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

Integrating Crystal Report with JSP

This article will discuss about how you may integrate your crystal reports with JSP pages and also show how to generate a crystal report

[close]

You didn't like the quality of this content?

Would you like to comment what you didn't like?

Crystal Reports is a dynamic reporting tool. It is a business intelligence reporting tools that used to design and generate reports from a range of data sources like oracle and MySQL. Crystal Reports establish a connection with Java and j2ee framework to display variety of report. Crystal Reports can works with .Net framework. Crystal Reports for Visual Studio .NET is one of the standard reporting tool for Visual Studio .NET; the main facility of it the light weight. It can produce interactive and dynamic report, deplorable presentation quality content that has been the strength and powerful mechanism of Crystal Reports for years to the .NET platform.

So, if we think dynamically, Crystal Reports can works with Java and .Net framework.

Now, in these articles we will show how to generate a crystal report. We need to install the Crystal Report software to our machine to use the reporting tool. At first, we need to make a connection with the database server. We open a report design file and establish a connection with the required database.

Database

Figure 1: Database

After establish the connection, we need to write down the SQL query, depending on our requirement. We can able to pass any parameter, if we need to preview data upon any condition. Crystal Reports has Database Expert. By using the Database Expert, anyone can select and link variety of tables from the data sources, including Microsoft PowerPoint and Microsoft Excel spreadsheets, Oracle databases, Business Objects Enterprise business views, and local file system information. The Database Expert helps you to add any parameters and filters within the report. . At first need to make a data source. Depending on our requirement, we will develop a SQL query. Here we will provide the screen short of it. As per your requirement, you generate the data source. Most of the time, ‘Jsp’ pages use pass any parameter. You can add any filter as per your requirement; this helps you to retrieve some data which want to show. Parameters and filters are important to design a report.

Sql query Examples

Figure 2: Sql query Examples

With the preview of SQL, we find two parameters named ‘bo_folio’ and ‘mdate’. We will show the process how to send the parameter’s value and make interconnection with jsp and Crystal Report.

We can able to drag and drop facilities in this reporting section. Crystal Reports provide the facilities of graphically design data connection(s) and design report layout. Crystal Reports provides the facilities to generate chart report like pie chart, bar chat, line chart etc. In the Crystal Reports design pattern we can add labels, grid, table and chart by drag and drop process. So, we just need to follow how to add the fields in the design layout.

Table

Figure 3: Table

Fields from these tables can be placed on the report design surface, and can also be used in custom formulas, using either BASIC or Crystal's own syntax, that is then placed on the design surface. Formulas can be evaluated at several phases during report generation as specified by the developer. This jsp page is used to call the ‘Omnibus.jsp’ page. When we call the jsp page we will send two parameters that must for building the report. In the next jsp page there is show down two fields that’s inter connect with Crystal Report. Edit Data Set displays the columns you specified in the query, and provides options for editing the data set. Then, choose Preview Results to make sure the query is valid and that it returns the correct data. If you typed the SELECT statement correctly, you should see the results that are shown in the preview. This helps you to design the Crystal Report. It is very east to add any line and label in the report. This helps the designer lots to develop Crystal Report easily.

Listing 1: JSPcode:

<%@ pageerrorPage="CommonError.jsp" %>
<jsp:useBean id="cm"  class="batbsms.conBean"/>
<LINK REL=stylesheet href="<%=request.getContextPath()%>/js/common.css" TYPE="text/css"></LINK>
<% if(String.valueOf(session.getAttribute("UserName")).equals("null"))
   {
%><script>top.location = "<%=request.getContextPath()%>/Index.jsp"</script>
<%}%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Omnibus Group List</title>
<SCRIPT LANGUAGE="JavaScript" SRC="<%=request.getContextPath()%>/js/common.js"></SCRIPT><SCRIPT LANGUAGE="JavaScript" SRC="<%=request.getContextPath()%>/js/datetimepicker.js"></SCRIPT><LINK REL=stylesheet href="<%=request.getContextPath()%>/js/common.css" TYPE="text/css"></LINK>
<script language="javascript">
<!--
functionSubmitThis() {
var count = 0;
var e = document.getElementById("dateselect");
var f = document.getElementById("omnibusName");
varstrUser = e.options[e.selectedIndex].value;
var strUser1 = f.options[f.selectedIndex].value;
if(strUser==null)
   {
alert('Declaration Date must be entered');
return false;
   }
if(strUser=='')
   {
alert('Declaration Date must be entered');
return false;
   }
if(strUser1==null)
    {
alert('Omnibus Name  must be entered');
return false;
    }
if(strUser1=='')
     {
alert('Omnibus Name must be entered');
return false;
     }
if (count == 0)
  {
document.forms[0].action="<%=request.getContextPath()%>/Omnibus.jsp";
document.forms[0].submit();
  } else{
ShowAllAlertMsg();
return false;
   }
}function refresh()
{location="<%=request.getContextPath()%>/jsp/Omnibus/group/reportOmnibus.jsp";
}
//-->
</script>
</head>
<body TEXT="000000" BGCOLOR="FFFFFF">
<%
booleanisConnect = cm.connect();
if(isConnect==false){
     %>
<jsp:forward page="ErrorMsg.jsp" >
<jsp:param name="ErrorTitle" value="Connection Failure" />
<jsp:param name="ErrorHeading" value="Connection Problem" />
<jsp:param name="ErrorMsg" value="Error : Connection Failed, Please contact the System Administrator" />
</jsp:forward>
<%
     }
%>
<form action="<%=request.getContextPath()%>/Omnibus.jsp" method="post" name="FileForm">
<span class="style7">
<table width="100%" BORDER=1  cellpadding="5"  style="border-collapse: collapse" bordercolor="#0044B0">
<!--DWLayoutTable-->
<tr><td bgcolor="#0044B0" class="style7">Omnibus Report</td></tr>
<trbgcolor="#E8F3FD" >
<td height="100%" bgcolor="#E8F3FD"  ><center>
<br>
<div align="left">
<table width="80%"  border="0" cellpadding="5">
<tr>
<th scope="row" width="44%"><div align="left" class="style8">    Date of Declaration</div></th>
<td width="1%">:</td>
<td><div align="left">
<select name="dateselect" class="SL1TextFieldListBox">
<option>--- Please Select ---</option>
<%
           String thedate = "";
String query1 = "SELECT DISTINCT ISSUE_DATE FROM DIVIDEND_VIEW ORDER BY ISSUE_DATE DESC";
cm.queryExecute(query1);

while(cm.toNext())
              {
thedate = cm.getColumnDT("ISSUE_DATE");
                 %>
<option value="<%=thedate%>"><%=thedate%></option>
<%
              }
            %>
</select>
</div></td>
</tr>
<tr>
<th scope="row" width="44%"><div align="left" class="style8">    Omnibus</div></th>
<td width="1%">:</td>
<td><div align="left">
<select name="omnibusName" class="SL1TextFieldListBox">
<option>--- Please Select ---</option>
<%
              String oid = "";
              String oname = "";
String query2 = "SELECT REC_ID, NAME FROM OMNIBUS_CONFIG ORDER BY NAME ASC";
cm.queryExecute(query2);

while(cm.toNext())
              {
oid=cm.getColumnS("REC_ID");
oname=cm.getColumnS("NAME");
                                 %>
<option value="<%=oid%>"><%=oname%></option>
<%
              }%>
</select>
</div></td>
</tr>
</table>
<br>
</div>
<table width="50%" BORDER=0  cellpadding="15" style="border-collapse: collapse" bordercolor="#EAC06B">
<tr>
<th width="50%" scope="row">
<div align="right">
	<img name="B2" src="<%=request.getContextPath()%>/images/btnRefresh.gif" onclick="reset()" onMouseOver="document.forms[0].B2.src = '<%=request.getContextPath()%>/images/btnRefreshOn.gif'" onMouseOut="document.forms[0].B2.src = '<%=request.getContextPath()%>/images/btnRefresh.gif'">
</div></th>
<td width="50%" align="left">
	<img name="B1" src="<%=request.getContextPath()%>/images/btnOK.gif"  onclick="SubmitThis()" onMouseOver="document.forms[0].B1.src = '<%=request.getContextPath()%>/images/btnOKOn.gif'" onMouseOut="document.forms[0].B1.src = '<%=request.getContextPath()%>/images/btnOK.gif'">
</td>
</tr>
</table>
</form>
<%if (isConnect)
   {
cm.takeDown();
   }
%></body></html>

Both fields and formulas have a wide array of formatting options available that can be applied absolutely or conditionally. The data can be grouped into bands, each of that can be split further and conditionally suppressed as needed.

Crystal Reports also supports sub reports, graphing, and a limited amount of GIS functionality. In this section we pass two parameters. This file name is OmnibusReport.jsp.

You know,16 tools for CrystalReports in the most powerful, integrated, and easiest suite of tools to Edit, Analyze, Document, Modify, Migrate and Convert + more, one or many CrystalReports at the same time! . rpt Inspector can easily work with 1

CrystalReport

at a time, but its true power is working with multiple CrystalReports at the same time.

Listing 2: Defining Actions:

<script>
</script>
<%@ page errorPage="CommonError.jsp" %>
<jsp:useBean id="cm" class="batbsms.conBean"/>
<LINK REL=stylesheet href="<%=request.getContextPath()%>/js/common.css" TYPE="text/css"></LINK>
<% if(String.valueOf(session.getAttribute("UserName")).equals("null"))
   {%>
<script>top.location = "<%=request.getContextPath()%>/Index.jsp"</script>
<%
}
booleanisConnect = cm.connect();
if(isConnect==false)
 {
   %>
<jsp:forward page="ErrorMsg.jsp" >
<jsp:param name="ErrorTitle" value="Connection Failure" />
<jsp:param name="ErrorHeading" value="Connection Problem" />
<jsp:param name="ErrorMsg" value="Error : Connection Failed, Please contact the System Administrator" />
</jsp:forward>
<%
 }
%>
<%@ tagliburi="/crystal-tags-reportviewer.tld" prefix="crviewer" %>
<%@page language="java" import="java.util.Vector,java.util.StringTokenizer,java.text.SimpleDateFormat, java.lang.Object.*, java.math.*"%>
<%@page
import="java.util.Date,java.text.*,com.crystaldecisions.reports.reportengineinterface.*,
com.crystaldecisions.report.web.viewer.*,
com.crystaldecisions.sdk.occa.report.data.*,
com.crystaldecisions.sdk.occa.report.reportsource.*
"
contentType="text/html;charset=UTF-8"
%>
<html>
<head>
<title>
 Account Report
</title>
</head>
<body bgcolor="#ffffff">
<%
    //Value of parameter get from page SetBankReport.jsp
 String omnibusDate= String.valueOf(request.getParameter("dateselect"));
  String bo_folio_no= String.valueOf(request.getParameter("omnibusName"));
String reporturl = "";
  String markprinted = "";
booleanmp;
reporturl="/CR_Reports/Div_Collection/Omnibus.rpt";
String ulog = "call ADD_USER_LOG('" + String.valueOf(session.getAttribute("UserName")) + "','" + String.valueOf(session.getAttribute("UserRole")) + "','Printed Omnibus Report')";
booleanub = cm.procedureExecute(ulog);
if (!reporturl.equals("")) {
    //session.setAttribute("reportSource", null);
session.setAttribute("reportSource", null);
session.setAttribute("refreshed", null);
  }
Object reportSource = session.getAttribute("reportSource");
if (reportSource == null)
{
try{
  IReportSourceFactory2 rptSrcFactory = new JPEReportSourceFactory();
reportSource = rptSrcFactory.createReportSource(reporturl, request.getLocale());
session.setAttribute("reportSource", reportSource);
}catch (Exception e) {}
}CrystalReportViewer viewer= new CrystalReportViewer();
try{viewer.setReportSource(reportSource);
}catch (Exception e) {}
viewer.setHasViewList(false);
viewer.setDisplayGroupTree(false);
viewer.setEnableParameterPrompt(false);
viewer.setEnableDrillDown(false);
viewer.setHasToggleGroupTreeButton(false);
viewer.setPrintMode(CrPrintMode.ACTIVEX);
viewer.setLeft(10);
viewer.setOwnPage(true);
viewer.setReuseParameterValuesOnRefresh(true);
ParameterField param1 = new ParameterField();
param1.setReportName("");
param1.setName("bo_folio");
ParameterField param2 = new ParameterField();
param2.setReportName("");
param2.setName("mdate");
//ParameterField param2 = new ParameterField();
//param2.setReportName("");
//param2.setName("myaccnotype");
Values vals1 = new Values();
ParameterFieldDiscreteValue val1 = new ParameterFieldDiscreteValue();
val1.setValue(bo_folio_no);
vals1.add(val1);
Values vals2 = new Values();
ParameterFieldDiscreteValue val2 = new ParameterFieldDiscreteValue();
val2.setValue(omnibusDate);
vals2.add(val2);
param1.setCurrentValues(vals1);
param2.setCurrentValues(vals2);
Fields fields = new Fields();
fields.add(param1);
fields.add(param2);
viewer.setParameterFields(fields);
if (session.getAttribute("refreshed") == null)
{
viewer.refresh();
session.setAttribute("refreshed", "true");
}
//viewer.refresh();
try
{
viewer.processHttpRequest(request, response, getServletConfig().getServletContext(), null);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
if (isConnect)
  {
cm.takeDown();
  }
%>
</body>
</html>
Report

Figure 4: Report

By using this two jsp pages we can send the parameters and execute the Crystal report. Crystal report is very user friendly and light weight, so we can use it by installing in our local machine. To get the facilities of this report we need to add some jar files to the projects. This is the total preview how we able to run a crystal report in j2ee server.

This is all for this article. Hope you liked, see you next time.



My main area of specialization is Java and J2EE. I have worked on many international projects like Recorders,Websites,Crawlers etc.Also i am an Oracle Certified java professional as well as DB2 certified

What did you think of this post?

Did you like the post?

Help us to keep publishing good contents like this.

SUPPORT US

funded

remaining

[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually � in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits � in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login