无法在jsp中加载BIRT图表

时间:2014-01-15 09:40:32

标签: java jsp charts birt

我把问题加载BIRT图表报告到jsp ..如果我使用表格为我的报告它将显示不错,但当我更改为图表它只是在我的jsp..how显示空白页面我能解决这个问题吗? ?

这是我的html渲染。

public Resolution htmlReport() throws EngineException, SemanticException {
            ByteArrayOutputStream reportOutput = new ByteArrayOutputStream();

            String path = getCompassContext().getServletContext().getRealPath(
                    "/report");

            // @TODO
            String user = getCompassContext().getUser().getUsername();
            birtReport.setUser(user);
            birtReport.setBirtEngine(getCompassContext().getBirtEngine());

            path = CompassConfig.getBirtReport(); //+ "/login_time.rptdesign";
            birtReport.setReportDesignPath(path);
            birtReport.setReportDesignName("/test.rptdesign");
            /**
             * Generates the html report.
             * 
             * @return forward to the jsp page
             * @throws EngineException when opening report design or reunning the report
             * @throws SemanticException when changing properties of DesignElementHandle
             */
             // set output options
                IHTMLRenderOption options = new HTMLRenderOption();

                options.setOutputFormat(IHTMLRenderOption.OUTPUT_FORMAT_HTML);
                options.setOutputStream(reportOutput);
                options.setEmbeddable(false);
               // options.setBaseImageURL(context.getRequest().getContextPath() + "/images");
               //options.setImageDirectory(context.getServletContext().getRealPath("/images"));
                options.setImageHandler(new HTMLServerImageHandler());
                options.setMasterPageContent(true);

               birtReport.generateReport(options);

                return new StreamingResolution("text/html", new ByteArrayInputStream(reportOutput.toByteArray()));
            }

这是我的BIRT引擎

public void generateReport(IRenderOption options) throws EngineException,
            SemanticException {

        generateParamaters();

        // get the engine
        IReportEngine birtReportEngine = birtEngine;

        // open the report design
        String path = reportDesignPath + "/" + reportDesignName;
        IReportRunnable design = birtReportEngine.openReportDesign(path);

        // create task to run and render report
        IRunAndRenderTask task = birtReportEngine
                .createRunAndRenderTask(design);

        Map<String, Object> appContext = task.getAppContext();
        Connection con = DataSourceUtils.getConnection();
        appContext.put("OdaJDBCDriverPassInConnection", con);

        HashMap<String, String[]> multiValParam = getMultiValParam();
        if(multiValParam != null && multiValParam.size() > 0) {
            Set<String> key = multiValParam.keySet();
            Iterator<String> ite = key.iterator();

            while(ite.hasNext()) {
                String paramName = (String) ite.next();
                String[] paramValues = multiValParam.get(paramName);

                task.setParameterValue(paramName, paramValues);
            }
        }
        task.setParameterValues(getParameter());
        task.setRenderOption(options);
        task.setAppContext(appContext);

        // run report
        task.run();
        task.close();
    }

真的需要帮助!!!!

1 个答案:

答案 0 :(得分:0)

我已经找到了答案..你需要将html渲染放在setEmbeddable(true)下面

options.setBaseImageURL(getCompassContext()。getRequest()。getContextPath()+“/ images”); options.setImageDirectory(getCompassContext()的getServletContext()getRealPath( “/图像”));

并且需要将此代码放在appContext.put

下面的生成报告中

DesignElementHandle reportChart = design.getDesignHandle()。getModuleHandle()。findElement(“reportChart”);