在Crystal报表中更改数据库连接

时间:2018-01-27 08:00:47

标签: java c# jsp crystal-reports sap

我在jsp中使用水晶报告。当我在SAP水晶报告中设计报告时,我设置了数据库连接。现在我想在呈现报表时更改连接字符串。连接字符串来自web.xml,任何配置或编程方式。

这是我的项目结构

enter image description here

我的web.xml

    <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>Report_Viewer</display-name>
  <context-param>
        <param-name>crystal_image_uri</param-name>
        <param-value>/crystalreportviewers</param-value>
    </context-param>
    <context-param>
        <param-name>crystal_image_use_relative</param-name>
        <param-value>webapp</param-value>
    </context-param>
    <servlet>
        <servlet-name>CrystalReportViewerServlet</servlet-name>
        <servlet-class>com.crystaldecisions.report.web.viewer.CrystalReportViewerServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>CrystalReportViewerServlet</servlet-name>
        <url-pattern>/CrystalReportViewerHandler</url-pattern>
    </servlet-mapping>
    <resource-ref>
        <res-ref-name>jdbc/IntranetDBW</res-ref-name>
        <res-type>javax.sql.ConnectionPoolDataSource</res-type>
        <res-auth>Container</res-auth>
        <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

我的jsp

<%@ page import= "com.crystaldecisions.report.web.viewer.*,com.crystaldecisions.sdk.occa.report.data.*" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.lib.*"%>
<%@ page import="com.crystaldecisions.sdk.occa.report.*"%>
<%@page import="com.crystaldecisions.reports.sdk.*" %>
<%@page import="com.crystaldecisions.sdk.occa.report.exportoptions.*" %>

<%
//open the report rpt file
String REPORT_NAME = "test_table.rpt";
ReportClientDocument reportClientDoc = new ReportClientDocument();
reportClientDoc.open(REPORT_NAME, 0);

//set up a viewer
CrystalReportViewer viewer = new CrystalReportViewer();
viewer.setOwnPage(true);
viewer.setOwnForm(true);
viewer.setPrintMode(CrPrintMode.ACTIVEX);

//pass it the report source
viewer.setReportSource(reportClientDoc.getReportSource());

//Render the report.
viewer.processHttpRequest(request, response, getServletConfig().getServletContext(), null); 
%>

0 个答案:

没有答案