Alyssa20
asked on
Reports show database logon page while accessing from web
I am using crystal reports advanced developer edition 10 with JSP deployed on tomcat.
Whenever user access's a report over the web(from JSP) she gets a database logon page which asks for a user name and password of database ( which is Oracle 8i).
Can this be avoided?
The problem with this is that, the query strings that are being passed to the report with the url gets lost when the user presses OK after entering user name and password.
Whenever user access's a report over the web(from JSP) she gets a database logon page which asks for a user name and password of database ( which is Oracle 8i).
Can this be avoided?
The problem with this is that, the query strings that are being passed to the report with the url gets lost when the user presses OK after entering user name and password.
ASKER
Thanks for replying.
I have JSP page in which i have soemthing like
<form name="form1" action="r.jsp">
<%
while(rs.next())
{
invoice_number = rs.getString("invoice_numb er");
... Fetching other values%>
<tr>
<td><input type="radio" name="invoice_number" value="<%=invoice_number%> "></td>
<td class="tdMain"><%=invoice_ number%></ td>
<<td class="tdMain"><%=dept_nam e%></td>
</tr>
<% }
</form>
When the user submits the form after selecting any radio button that invoice_number is passed as a parameter(the report will be geenratde for only this invoice_number).
Here is crystalReportsViewer.jsp
<code_starts_for_crystalRe portsViewe r.jsp>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import = "java.net.*, com.crystaldecisions.sdk.o cca.report .applicati on.ReportC lientDocum ent, com.crystaldecisions.repor t.web.view er.*"
%>
<%
// Create an Interactive Viewer
CrystalReportInteractiveVi ewer viewer = new CrystalReportInteractiveVi ewer();
viewer.setName("Crystal_Re port_Inter active_Vie wer");
viewer.setOwnForm(true);
viewer.setOwnPage(true);
viewer.setPrintMode(CrPrin tMode.PDF) ;
String queryString;
queryString = request.getQueryString();
requestURI, else set
if (queryString == null)
viewer.setURI(request.getR equestURI( ));
else
viewer.setURI(request.getR equestURI( ) + "?" + queryString);
viewer.setReportSource(cli entDoc.get ReportSour ce());
viewer.processHttpRequest( request, response, getServletConfig().getServ letContext (), out);
viewer.dispose();
%>
</code_ends_for_crystalRep ortsViewer .jsp>
Here is code for r.jsp
<code_starts_for_r.jsp>
<%@ page import="java.net.*, java.util.Calendar, java.util.*, com.crystaldecisions.sdk.o cca.report .data.*, com.crystaldecisions.sdk.o cca.report .applicati on.*, com.crystaldecisions.sdk.o cca.report .reportsou rce.IRepor tSource, com.crystaldecisions.sdk.o cca.report .lib.Repor tSDKExcept ion, com.crystaldecisions.repor t.web.view er.*"
%>
<html>
<body>
<%!
String invoice_number=null;
%>
<%@ include file="AlwaysRequiredSteps. jsp" %>
<%
invoice_number=request.get Parameter( "invoice_n umber");
ParameterFieldController paramController;
paramController = clientDoc.getDataDefContro ller().get ParameterF ieldContro ller();
paramController.setCurrent Value("", "invoice_number", invoice_number);
%>
<%@ include file="CrystalReportsViewer .jsp" %>
</body>
</html>
</code_ends_for_r.jsp>
Here is code for AlwaysRequiredSteps.jsp
<code_starts_for_AlwaysReq uiredSteps .jsp>
<%
String temp1 = (request.getRequestURI()). replace('/ ', '\\');
String path = request.getRealPath("/") + temp1; // Get the physical path of the application dir
int lastIndex = path.lastIndexOf("\\"); // Give us index of last occurring '\' in string
path = path.substring(0, lastIndex) + "\\"; // Get substring beginning from first char to last index of '\'
ReportAppSession ra = new ReportAppSession();
ra.createService("com.crys taldecisio ns.sdk.occ a.report.a pplication .ReportCli entDocumen t");
ra.setReportAppServer("127 .0.0.1");
ra.initialize();
ReportClientDocument clientDoc = new ReportClientDocument();
clientDoc.setReportAppServ er(ra.getR eportAppSe rver() );
clientDoc.open(path + reportName, OpenReportOptions._openAsR eadOnly);
%>
</code_ends_for_AlwaysRequ iredSteps. jsp>
I have JSP page in which i have soemthing like
<form name="form1" action="r.jsp">
<%
while(rs.next())
{
invoice_number = rs.getString("invoice_numb
... Fetching other values%>
<tr>
<td><input type="radio" name="invoice_number" value="<%=invoice_number%>
<td class="tdMain"><%=invoice_
<<td class="tdMain"><%=dept_nam
</tr>
<% }
</form>
When the user submits the form after selecting any radio button that invoice_number is passed as a parameter(the report will be geenratde for only this invoice_number).
Here is crystalReportsViewer.jsp
<code_starts_for_crystalRe
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import = "java.net.*, com.crystaldecisions.sdk.o
%>
<%
// Create an Interactive Viewer
CrystalReportInteractiveVi
viewer.setName("Crystal_Re
viewer.setOwnForm(true);
viewer.setOwnPage(true);
viewer.setPrintMode(CrPrin
String queryString;
queryString = request.getQueryString();
requestURI, else set
if (queryString == null)
viewer.setURI(request.getR
else
viewer.setURI(request.getR
viewer.setReportSource(cli
viewer.processHttpRequest(
viewer.dispose();
%>
</code_ends_for_crystalRep
Here is code for r.jsp
<code_starts_for_r.jsp>
<%@ page import="java.net.*, java.util.Calendar, java.util.*, com.crystaldecisions.sdk.o
%>
<html>
<body>
<%!
String invoice_number=null;
%>
<%@ include file="AlwaysRequiredSteps.
<%
invoice_number=request.get
ParameterFieldController paramController;
paramController = clientDoc.getDataDefContro
paramController.setCurrent
%>
<%@ include file="CrystalReportsViewer
</body>
</html>
</code_ends_for_r.jsp>
Here is code for AlwaysRequiredSteps.jsp
<code_starts_for_AlwaysReq
<%
String temp1 = (request.getRequestURI()).
String path = request.getRealPath("/") + temp1; // Get the physical path of the application dir
int lastIndex = path.lastIndexOf("\\"); // Give us index of last occurring '\' in string
path = path.substring(0, lastIndex) + "\\"; // Get substring beginning from first char to last index of '\'
ReportAppSession ra = new ReportAppSession();
ra.createService("com.crys
ra.setReportAppServer("127
ra.initialize();
ReportClientDocument clientDoc = new ReportClientDocument();
clientDoc.setReportAppServ
clientDoc.open(path + reportName, OpenReportOptions._openAsR
%>
</code_ends_for_AlwaysRequ
Sorry for the late reply.
I have gone through the code you have provided. The key reason that causing the missing of querystring are the below statement.
if (queryString == null)
viewer.setURI(request.getR equestURI( ));
else
viewer.setURI(request.getR equestURI( ) + "?" + queryString);
While the viewer request for database logon, the database details will be submitted into the same page, in your case will be "crystalReportsViewer.jsp" , so the content of the jsp will be rerun. please modify the code as the following:
if (queryString != null)
viewer.setURI(request.getR equestURI( ) + "?" + queryString);
If the above code cannot work, try to store the queryString in session or cookies and give it a unique id, then assign into URI when page is run.
Regards,
Zonique
I have gone through the code you have provided. The key reason that causing the missing of querystring are the below statement.
if (queryString == null)
viewer.setURI(request.getR
else
viewer.setURI(request.getR
While the viewer request for database logon, the database details will be submitted into the same page, in your case will be "crystalReportsViewer.jsp"
if (queryString != null)
viewer.setURI(request.getR
If the above code cannot work, try to store the queryString in session or cookies and give it a unique id, then assign into URI when page is run.
Regards,
Zonique
ASKER
Thanks for replying.
I have stored it using sessions.
But even now i want that the log on page should not appear again and again. Users don't like fillign the user name and passowrd every time they request a report.
Can this be avoided?
I have stored it using sessions.
But even now i want that the log on page should not appear again and again. Users don't like fillign the user name and passowrd every time they request a report.
Can this be avoided?
Use the following method:
clientDoc.getDatabaseContr oller().lo gon( sUser, sPassword );
clientDoc.getDatabaseContr
ASKER
Thanks
I tried ur code but it's giving no result.
The behaviour is same as before.
I put the it in AlwaysRequiredSteps.jsp
I tried ur code but it's giving no result.
The behaviour is same as before.
I put the it in AlwaysRequiredSteps.jsp
Is that mandatory to use the Interactive Viewer, because by using that viewer, i don't think the property of setDatabaseLogonInfos provided by ReportServerControl is applicable for this viewer as for other viewers do.
Anyway, you can have a try. i will provide 2 way of achieving the purpose as following.
//For using viewer other than Interactive viewer only ( i grap it from crystal documentation, a simple way of setting up the ConnectionInfos)
//Create the ConnectionInfos object to store the database logon Information
ConnectionInfos connInfos = new ConnectionInfos();
//Create a ConnectionInfo object for each database logon you want to set.
IConnectionInfo connInfo1 = new ConnectionInfo();
//Set the database logon information for each ConnectionInfo object.
connInfo1.setUserName("use r");
connInfo1.setPassword("pas sword");
//Add each ConnectionInfo object to the ConnectionInfos collection.
//The ConnectionInfos object can now be used to set the database logon information for a report.
connInfos.add(connInfo1);
//Set the database logon information by passing the viewer the initialized ConnectionInfos object.
viewer.setDatabaseLogonInf os(connInf os);
viewer.setEnableLogonPromp t(false);
//For Interactive viewer or other, step will be abit complicated
//Retrieve the ConnectionInfos object
PropertyBag pBag = new PropertyBag();
pBag.putBooleanValue( "All", true );
ConnectionInfos connInfos = clientDoc.getDatabaseContr oller().ge tConnectio nInfos( pBag );
//Loop through every ConnectionInfo and set it logon details
for( int i=0; i<connInfos.size(); i++){
IConnectionInfo connInfo = connInfos.getConnectionInf o(i);
connInfo.setUserName( "user" );
connInfo.setPassword( "password" );
}
//Set the ConnectionInfos object back into Report
try{
clientDoc.getDatabaseContr oller().se tConnectio nInfos( connInfos );
} catch ( ReportSDKException e ){
//Do something here
}
Hope this is help.
Regards,
Zonique
Anyway, you can have a try. i will provide 2 way of achieving the purpose as following.
//For using viewer other than Interactive viewer only ( i grap it from crystal documentation, a simple way of setting up the ConnectionInfos)
//Create the ConnectionInfos object to store the database logon Information
ConnectionInfos connInfos = new ConnectionInfos();
//Create a ConnectionInfo object for each database logon you want to set.
IConnectionInfo connInfo1 = new ConnectionInfo();
//Set the database logon information for each ConnectionInfo object.
connInfo1.setUserName("use
connInfo1.setPassword("pas
//Add each ConnectionInfo object to the ConnectionInfos collection.
//The ConnectionInfos object can now be used to set the database logon information for a report.
connInfos.add(connInfo1);
//Set the database logon information by passing the viewer the initialized ConnectionInfos object.
viewer.setDatabaseLogonInf
viewer.setEnableLogonPromp
//For Interactive viewer or other, step will be abit complicated
//Retrieve the ConnectionInfos object
PropertyBag pBag = new PropertyBag();
pBag.putBooleanValue( "All", true );
ConnectionInfos connInfos = clientDoc.getDatabaseContr
//Loop through every ConnectionInfo and set it logon details
for( int i=0; i<connInfos.size(); i++){
IConnectionInfo connInfo = connInfos.getConnectionInf
connInfo.setUserName( "user" );
connInfo.setPassword( "password" );
}
//Set the ConnectionInfos object back into Report
try{
clientDoc.getDatabaseContr
} catch ( ReportSDKException e ){
//Do something here
}
Hope this is help.
Regards,
Zonique
Before you try on the code i provided, could you please check on the RAS server's connection to the production database. If the report using DSN, make sure there is the same DSN name is created in RAS Server.
Regards,
Zonique
Regards,
Zonique
ASKER
>>Before you try on the code i provided, could you please check on the RAS server's connection to the production database. If the report using DSN, make sure there is the same DSN name is created in RAS Server.
I don't have any DSN there. I connect to the database using the wizard. When i design the report using the wizard it takes me to the window where i select "Create Connection" . Further I select "Oracle Server", which gives me another window where i enter the user name, password and Service. This connects the report to the server. I have created no seperate DSN for connection.
I think u are absolutely right. This may be causing the problem. But how do i correct it.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank u so much Zonique.
You are great
You are great
I am not sure how you setup your CRViewer, since you did not disclose that portion of codes.
Anyway, did you include your query string in "URI" property from the viewer. By setting up this property, the viewer will post to the value you specified in URI together with the query string stated.
Regards,
Zonique