Link to home
Start Free TrialLog in
Avatar of Alyssa20
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.

Avatar of kennyvoon
kennyvoon

Hi Alyssa,

    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
Avatar of Alyssa20

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_number");
      ... 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_name%></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_crystalReportsViewer.jsp>

<%@ page contentType="text/html; charset=utf-8" %>
<%@ page import = "java.net.*,                  com.crystaldecisions.sdk.occa.report.application.ReportClientDocument, com.crystaldecisions.report.web.viewer.*"
%>

<%

// Create an Interactive Viewer
CrystalReportInteractiveViewer viewer = new CrystalReportInteractiveViewer();
viewer.setName("Crystal_Report_Interactive_Viewer");
viewer.setOwnForm(true);
viewer.setOwnPage(true);
viewer.setPrintMode(CrPrintMode.PDF);

String queryString;
queryString = request.getQueryString();
requestURI, else set
if (queryString == null)
 viewer.setURI(request.getRequestURI());
else
 viewer.setURI(request.getRequestURI() + "?" + queryString);

viewer.setReportSource(clientDoc.getReportSource());
viewer.processHttpRequest(request, response, getServletConfig().getServletContext(), out);
viewer.dispose();
%>
</code_ends_for_crystalReportsViewer.jsp>

Here is code for r.jsp

<code_starts_for_r.jsp>
<%@ page import="java.net.*,  java.util.Calendar,  java.util.*,  com.crystaldecisions.sdk.occa.report.data.*,  com.crystaldecisions.sdk.occa.report.application.*,  com.crystaldecisions.sdk.occa.report.reportsource.IReportSource,  com.crystaldecisions.sdk.occa.report.lib.ReportSDKException,  com.crystaldecisions.report.web.viewer.*"
%>

<html>
<body>
<%!
String invoice_number=null;
%>

<%@ include file="AlwaysRequiredSteps.jsp" %>

<%
invoice_number=request.getParameter("invoice_number");
ParameterFieldController paramController;
paramController = clientDoc.getDataDefController().getParameterFieldController();
paramController.setCurrentValue("", "invoice_number", invoice_number);
%>
<%@ include file="CrystalReportsViewer.jsp" %>
</body>
</html>
</code_ends_for_r.jsp>

Here is code for AlwaysRequiredSteps.jsp
<code_starts_for_AlwaysRequiredSteps.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.crystaldecisions.sdk.occa.report.application.ReportClientDocument");
ra.setReportAppServer("127.0.0.1");
ra.initialize();
ReportClientDocument clientDoc = new ReportClientDocument();
clientDoc.setReportAppServer(ra.getReportAppServer() );
clientDoc.open(path + reportName, OpenReportOptions._openAsReadOnly);
%>
</code_ends_for_AlwaysRequiredSteps.jsp>

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.getRequestURI());
else
 viewer.setURI(request.getRequestURI() + "?" + 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.getRequestURI() + "?" + 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
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?

Use the following method:

clientDoc.getDatabaseController().logon( sUser, sPassword );
Thanks
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("user");
connInfo1.setPassword("password");

//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.setDatabaseLogonInfos(connInfos);
viewer.setEnableLogonPrompt(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.getDatabaseController().getConnectionInfos( pBag );

//Loop through every ConnectionInfo and set it logon details
for( int i=0; i<connInfos.size(); i++){
      IConnectionInfo connInfo = connInfos.getConnectionInfo(i);

      connInfo.setUserName( "user" );
      connInfo.setPassword( "password" );
}

//Set the ConnectionInfos object back into Report
try{
      clientDoc.getDatabaseController().setConnectionInfos( connInfos );
} 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

>>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
Avatar of kennyvoon
kennyvoon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank u so much Zonique.
You are great