0

我使用下面的动作类方法来调用具有碧玉报告的java类。

    public ActionForward execute(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    BasicConfigurator.configure();
    DynaValidatorForm af = (DynaValidatorForm) form;
    HttpSession session = request.getSession(true);
    Connection conn = null;
    DatabaseUtility dataUtil = null;
    try {
        String empNo = af.getString("empNo").toString();
        String sd = af.getString("startDate").toString();
        String ed = af.getString("endDate").toString();

        String dbURL = getServlet().getServletContext().getInitParameter("dbURL");
        String dbUserName = getServlet().getServletContext().getInitParameter("dbUserName");
        String dbPassword = getServlet().getServletContext().getInitParameter("dbPassword");
        String JDBC = getServlet().getServletContext().getInitParameter("jdbcDriver");
        //create a map of parameters to pass to the report.
        ReportCaller.AttendanceReportPDF(dbURL, dbUserName, dbPassword, JDBC);

    } catch (Exception ex) {
    }
    return mapping.findForward(SUCCESS);
}

这是我的 ReportCaller 类,用于调用 jasper 报告

    public static void AttendanceReportPDF(String url, String un, String pw, String JDBC) {
    Connection conn = null;
    DatabaseUtility dataUtil = null;
    String reportSource = "./web/CompiledReport/report3.jasper";
    String reportDest = "../HelloReportWorld.pdf";
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("empNo", "00003");
    try {
        dataUtil = new DatabaseUtility(url, un, pw, JDBC);
        conn = DatabaseUtility.connect();
        // Fill the report using an empty data source
        JasperPrint jasperPrint = JasperFillManager.fillReport(reportSource, params, conn);
        System.out.println("After jasper print");
        // Create a PDF exporter
        JRExporter exporter = new JRPdfExporter();

        // Configure the exporter (set output file name and print object)
        exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, reportDest);
        exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

        // Export the PDF file
        exporter.exportReport();
        JasperViewer.viewReport(jasperPrint, false);
        System.out.println("This is the end");
    } catch (JRException ex) {
        logger.trace("Jasper Exception", ex);
    } catch (Exception e) {
        logger.trace("Exception ", e);
    }
}

这是我的 struts 动作映射

        <action 
    input="/Reports/AttendancePDF.jsp" 
    name="AttendancePDFReportActionForm" 
    path="/attendancePDFReport" 
    scope="session" 
    type="com.action.AttendancePDFReportAction">
        <result name="success" type="jasper">
            <param name="location">/CompiledReport/report3.jasper</param>
            <param name="dataSource">params</param>
            <param name="format">PDF</param>
        </result>
    </action>
</action-mappings>

当我运行项目(从 Netbeans 开发)时,我没有得到任何输出。在控制台上它说

WARN org.apache.struts.action.ActionMapping  - Unable to find 'success' forward.

此代码没有错误或异常。它运行完美,没有任何输出。但是当我在同一个环境中运行同一个java类而不使用struts时。然后 PDF 生成没有任何模糊。如果有人遇到类似问题找到解决方案并发布它,那就太好了。

4

0 回答 0