1

以下はjspでの私のコードです。アプリケーションを実行してレポートを表示しようとすると、Crystal Report Viewer がデータベース ログオン ウィンドウをポップアップ表示します。ユーザー名とパスワードを入力すると、null ポインター例外がスローされます。何が問題なのですか?パラメーター、つまり口座番号、日付から日付までが null ではありません。

<%@page import="com.crystaldecisions.sdk.occa.report.application.ReportClientDocument"%>
<%@page import="com.crystaldecisions.sdk.occa.report.application.DatabaseController"%>
<%@page import="com.crystaldecisions.sdk.occa.report.application.DBOptions"%>
<%@page import="com.crystaldecisions.sdk.occa.report.exportoptions.ReportExportFormat"%>
<%@page import="com.crystaldecisions.sdk.occa.report.exportoptions.ExportOptions"%>
<%@page import="com.opensymphony.xwork2.ActionContext"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@ page import="com.crystaldecisions.report.web.viewer.*" %>
<%@ page import="com.crystaldecisions.sdk.occa.report.data.*"  %>
<%@page import="com.crystaldecisions.sdk.occa.report.reportsource.*"%>
<%@page import="com.crystaldecisions.sdk.occa.report.lib.*" %>


<%@page import="java.io.*"%>

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>


<%

    try {
        String account = ActionContext.getContext().getSession().get("account").toString();
        String frm_date = ActionContext.getContext().getSession().get("frm_date").toString();
        String to_date = ActionContext.getContext().getSession().get("to_date").toString();

        //System.out.println("From report Viewer "+account+" "+frm_date+" "+to_date);

        String reportName = "rpt_dp_customer_estmt1.rpt";
        File reportFile = new File(reportName);
        System.out.println("Path: " + reportFile.getAbsolutePath());
//check to see if the report source already exists
        Object reportSource = null; //session.getAttribute("reportSource");
//if the report source has not been opened
        //if (reportSource == null) {
//---------- Create a ReportClientDocument -----------
        ReportClientDocument oReportClientDocument = new ReportClientDocument();
//---------- Set the path to the location of thereport soruce -------------
//Open report.

        oReportClientDocument.open(reportName, 0);


        //parameters
        //}
        Fields fields = new Fields();

        ParameterField acc = new ParameterField();
        Values a_vals = new Values();
        ParameterFieldDiscreteValue acc_field = new ParameterFieldDiscreteValue();
        acc.setName("I_ACCT_NO");
        acc.setReportName("");
        acc_field.setValue(account);
        a_vals.add(acc_field);
        acc.setCurrentValues(a_vals);

        String fr_date = "07/07/2001";
        SimpleDateFormat ft = new SimpleDateFormat("mm/dd/yyyy");

        ParameterField f_date = new ParameterField();
        Values f_date_vals = new Values();
        ParameterFieldDiscreteValue f_date_field = new ParameterFieldDiscreteValue();
        f_date.setName("I_START_DATE");
        f_date.setReportName("");
        f_date_field.setValue(ft.parse(frm_date));
        f_date_vals.add(f_date_field);
        f_date.setCurrentValues(f_date_vals);

        String tr_date = "07/07/2012";

        ParameterField t_date = new ParameterField();
        Values t_date_vals = new Values();
        ParameterFieldDiscreteValue t_date_field = new ParameterFieldDiscreteValue();
        t_date.setName("I_END_DATE");
        t_date.setReportName("");
        t_date_field.setValue(ft.parse(to_date));
        t_date_vals.add(t_date_field);
        t_date.setCurrentValues(t_date_vals);


        fields.add(acc);
        fields.add(f_date);
        fields.add(t_date);

        //infos go here
        final String DBUSERNAME = "ESTATEMENT";
        final String DBPASSWORD = "estatement";

        final String CONNECTION_STRING = "!oracle.jdbc.driver.OracleDriver!jdbc:oracle:thin:ESTATEMENT/estatement@192.168.100.240:1521:RUBIKON";
        final String TRUSTEDCON = "false";
        final String PREQESERVERNAME = "192.168.100.240";
        final String SERVERTYPE = "JDBC (JNDI)";
        final String DATABASE_DLL = "crdb_jdbc.dll";
        final String DATABASE = "FINCALIVE";
        final String DBCLASSNAME = "oracle.jdbc.driver.OracleDriver";
        final String USEJDBC = "true";
        final String DATABASE_NAME = "FINCALIVE";
        final String SERVERNAME = "192.168.100.240:1521:RUBIKON";
        final String CONNECTIONURL = "jdbc:oracle:thin:ESTATEMENT/estatement@192.168.100.240:1521";
        final String SERVER = "192.168.100.240:1521:RUBIKON";
//Open report.


// Set DB Username and Password

        oReportClientDocument.getDatabaseController().logon(DBUSERNAME, DBPASSWORD);

// Create the two connectioninfo objects to use
        IConnectionInfo oldConnectionInfo = new ConnectionInfo();
        IConnectionInfo newConnectionInfo = new ConnectionInfo();

        // Assign the old Connection info to the reports current info
        DatabaseController dbController = oReportClientDocument.getDatabaseController();
        oldConnectionInfo = dbController.getConnectionInfos(null).getConnectionInfo(0);

        // If this connection needed parameters, we would use this field. 
        Fields pFields = null;

        // Create a new propertybag for the new location
        PropertyBag boPropertyBag1 = new PropertyBag();

// Set new table logon properties
        boPropertyBag1.put("URI", CONNECTION_STRING);
        boPropertyBag1.put("Trusted_Connection", TRUSTEDCON);
        boPropertyBag1.put("PreQEServerName", PREQESERVERNAME);
        boPropertyBag1.put("Server Type", SERVERTYPE);
        boPropertyBag1.put("Database DLL", DATABASE_DLL);
        boPropertyBag1.put("Database", DATABASE);
        boPropertyBag1.put("Database Class Name", DBCLASSNAME);
        boPropertyBag1.put("Use JDBC", USEJDBC);
        boPropertyBag1.put("Database Name", DATABASE_NAME);
        boPropertyBag1.put("Server Name", SERVERNAME);
        boPropertyBag1.put("Connection URL", CONNECTIONURL);
        boPropertyBag1.put("Server", SERVER);
        boPropertyBag1.put("Use JDBC", "true");

// Assign the properties to the connection info
        newConnectionInfo.setAttributes(boPropertyBag1);

// Set the DB Username and Pwd
        newConnectionInfo.setUserName(DBUSERNAME);
        newConnectionInfo.setPassword(DBPASSWORD);

// The Kind of connectionInfos is SQL
        newConnectionInfo.setKind(ConnectionInfoKind.SQL);

// set the parameters to replace.
// The 4 options are:
// _doNotVerifyDB
// _ignoreCurrentTableQualifiers
// _mapFieldByRowsetPosition
// _useDefault 
        int replaceParams = DBOptions._ignoreCurrentTableQualifiers + DBOptions._doNotVerifyDB;

// Now replace the connections 
        dbController.replaceConnection(oldConnectionInfo, newConnectionInfo, fields, replaceParams);

        oReportClientDocument.getDatabaseController().replaceConnection(oldConnectionInfo, newConnectionInfo, fields, replaceParams);

        System.out.println("Connection Replaced");
        ReportExportControl exporter = new ReportExportControl();

// set the report source
        reportSource = oReportClientDocument.getReportSource();
        exporter.setReportSource(reportSource);

        ExportOptions exportOptions = new ExportOptions();
        exportOptions.setExportFormatType(ReportExportFormat.PDF);
        exporter.setExportOptions(exportOptions);
        exporter.setParameterFields(fields);
// tell the viewer to display the report
        exporter.processHttpRequest(request,
                response,
                getServletConfig().getServletContext(),
                null);
        //create the CrystalReportViewer object
        /*CrystalReportViewer oCrystalReportViewer = new CrystalReportViewer();

        //Get the report source
        reportSource = oReportClientDocument.getReportSource();

        //set the reportsource property of the viewer
        oCrystalReportViewer.setReportSource(reportSource);
        //set viewer attributes
        oCrystalReportViewer.setOwnPage(true);

        //set the CrystalReportViewer print mode
        oCrystalReportViewer.setPrintMode(CrPrintMode.ACTIVEX);

        oCrystalReportViewer.setParameterFields(fields);

        oCrystalReportViewer.setEnableParameterPrompt(true);
        //refresh the CrystalReportViewer if necessary (only required once)
        if (session.getAttribute("refreshed") == null) {
        oCrystalReportViewer.refresh();
        session.setAttribute("refreshed", "true");
        }

        oCrystalReportViewer.setZoomFactor(100);
        oCrystalReportViewer.processHttpRequest(request, response,
        getServletConfig().getServletContext(), null);*/
    } catch (ReportSDKException e) {
        out.print(e);
    }
%>

そしてスタックトレースは

    WARNING: StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
    at org.apache.jsp.reportViewer_jsp._jspService(reportViewer_jsp.java:80)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:403)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:492)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:378)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:88)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
    at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:428)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
    at org.displaytag.filter.ResponseOverrideFilter.doFilter(ResponseOverrideFilter.java:125)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)
4

0 に答える 0