在现有的webapp中集成BIRT

问题描述 投票:6回答:2

我想将BIRT报告引擎添加到Tomcat中的现有webapp。我不需要BIRT查看器,我真的只想从http://localhost:8080/birt/output?__report=test.rptdesign&sample=my+parameter这样的网址运行报告,并使用不同的导出选项pdf,xls,doc,html。

到目前为止,我发现的集成指南都包括查看器和编写自己的servlet来处理不同的格式。

我希望有人知道我需要的报告引擎web.xml文件中的哪些servlet映射,以及我需要从现有webapp中的这个准系统BIRT实现的lib目录中包含哪些jar。

java tomcat birt
2个回答
17
投票

我希望有人知道我需要的报告引擎web.xml文件中的哪些servlet映射,以及我需要从现有webapp中的这个准系统BIRT实现的lib目录中包含哪些jar。

我不一定想编写自己的servlet我只想将现有的报告运行时从它自己的独立webapp(“运行时”按钮下的here)集成到我现有的webapp中,这样我就不必分发2个webapps了。支持运行BIRT报告。对不起,如果那不清楚。

我确实以最简单的方式解决了这个问题,以防任何人有类似的问题(使用BIRT运行时3.7.1):

  1. 您只需要将以下servlet映射添加到您自己的webapp\web-inf\web.xml文件中: <!-- Engine Servlet --> <servlet> <servlet-name>EngineServlet</servlet-name> <servlet-class>org.eclipse.birt.report.servlet.BirtEngineServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>EngineServlet</servlet-name> <url-pattern>/output</url-pattern> </servlet-mapping>
  2. web-inf\libruntime目录中的所有罐子包含在您自己的webapp\web-inf\lib目录中。

然后,您可以使用来自您自己的webapp的output BIRT报告URL运行.rptdesign文件,并指定您想要的任何格式,例如:

http://localhost:8080/myOwnWebapp/output?__report=test.rptdesign&__format=pdf
http://localhost:8080/myOwnWebapp/output?__report=test.rptdesign&__format=html
http://localhost:8080/myOwnWebapp/output?__report=test.rptdesign&__format=xls
http://localhost:8080/myOwnWebapp/output?__report=test.rptdesign&__format=doc
http://localhost:8080/myOwnWebapp/output?__report=test.rptdesign&__format=ppt

1
投票

据我了解,您正在尝试从servlet生成一个birt报告,其中* .rptdesign位于某个位置。

好,看看下面的代码

this.bundle = ResourceBundle.getBundle("com.tts.mersal.resources.MersalResources");
this.config = new EngineConfig();
this.config.setEngineHome(bundle.getString("BIRT_ENGINE_HOME"));
this.config.setLogConfig(bundle.getString("BIRT_LOGGING_FOLDER_PATH"), Level.ALL);
Platform.startup(config);
this.factory = (IReportEngineFactory)Platform.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
this.engine = factory.createReportEngine( config );
this.engine.changeLogLevel(Level.ALL);
ContentReader contentReader = Repository.getServiceRegistry(FacesContext.getCurrentInstance()).getFileFolderService().getReader(MersalOutboundReportDialogBean.this.dialogReportNode.getNodeRef());
IReportRunnable report = MersalOutboundReportDialogBean.this.getEngine().openReportDesign(contentReader.getContentInputStream());
ReportDesignHandle designHandle = (ReportDesignHandle)report.getDesignHandle();
OdaDataSource source = (OdaDataSource)designHandle.getModule().findDataSource(DATA_SOURCE_NAME);
source.setProperty(source.getPropertyDefn("FILELIST"), buildUrl((String)source.getProperty(designHandle.getModule(), "FILELIST")));
IRunAndRenderTask runAndRenderTask = MersalOutboundReportDialogBean.this.getEngine().createRunAndRenderTask(report);
HTMLRenderOption render = new HTMLRenderOption();
render.setOutputFileName("G:/Render.html");
render.setOutputFormat("html");
runAndRenderTask.setRenderOption(render);
runAndRenderTask.run(); 
runAndRenderTask.close();

正如您所看到的,您必须首先准备birt引擎,然后从IReportRunnable类型获取报告实例,这样您就可以在此之后使用therender选项设置输出的位置,该选项将根据您的请求进行更改。

您有多个chocies,HTMLRenderOption,PDFRenderOption等。

我希望能为你服务。

谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.