第十二章 BIRT报表的部署与配置

第十三章 BIRT报表引擎API及报表API 13.1报表引擎详解,API结构 BIRT包含几个引擎。一个引擎是一个提供一个特定领域的功能的一套Java API。例如,数据引擎包含管理数据的API,图表引擎包含生成一个图表的API。一般而言,BIRT包含四个引擎,报表设计引擎(design Engine),报表引擎(report engine),图表引擎(chat engine),数据引擎(data engine)。 a) 关于报表设 阅读详情

12.1 报表的工作模式以及相应的部署和配置

虽然为了示例的需要,在前文的第二章讲过BIRT的配置,以及在文本类报表,网格报表,图表中用过birt jsp tag,也做过一些说明。但报表的工作模式,不仅仅包含这两种。实际上,BIRT有五种工作模式,

第一种是用jsp或者javascript访问url,这个url遵循特定的格式,例如url/frameset?__report=&__paraname=paravalue;

第二种方式是在jsp页面中嵌入birt tag;

第三种模式是在servlet或者java class中打开用报表设计器设计的报表,导出一个html,pdf或者其它格式的文档的输出到既定的目录;

第四种是扩展报表展示器birt web viewer,也即是改写birt web viewer的servlet,配置访问路径,并用它来展示先前在报表设计器中设计的报表;

第五种模式即是在java class中利用报表设计API,生成报表设计文档,并用报表引擎API打开并生成html,pdf或者其它格式的文档。

本章先详细说明前文用到的两种工作模式,后面的三种,我们会在第十三章及之后的章节详细描述。

第一种工作模式:url

Url的一个例子如下:

http://localhost:8080/birt/frameset?__report=test.rptdesign&__bookmark=bk&__isreportlet=true

说明:

http://localhost:8080:代表访问的服务器地址

/birt :代表访问的app的根目录

/frameset: 代表访问的servlet的模式,在web.xml中有配置的说明

__report=test.rptdesign&__bookmark=bk&__isreportlet=true 代表访问的参数,其中birt保留的参数以两个下划线开头,例如__report指定报表的名称;__bookmark指定报表的书签;报表参数不需要以__开头。

报表访问servlet的模式,主要有以下几种:

 frameset ---- 采用Ajax框架,可以显示工具条,导航条和TOC面板,实现复杂的操作,如分页处理,导出数据,导出报表,打印等。该模式下会自动生成report document文件(预览report design文件)到特定的目录(用户可以用参数指定,也可以定义在web.xml里)。采用Ajax,速度较慢。

run ---- 也采用Ajax框架,但不实现frameset的复杂功能,不会生成临时的report document文件(预览report design文件),也不支持分页,这个主要是应用在BIRT Designer里的preview tab里,可以支持cancel操作,其它不怎么常用。采用Ajax,速度较慢。

preview --- 没有用到Ajax框架,直接调用底层Engine API对报表进行render,把生成的报表内容直接输出到浏览器。这种模式和run模式调用的是相同的Engine API,唯一区别在于run采用Ajax获取报表内容,而preview直接输出到浏览器。如果要支持分页,用户需要在URL上定义__page和__pagerange参数。需要特别说明的是,在这几种预览模式中,preview的速度是最快的。

download --- 用于导出报表数据,当你使用frameset工具条里的导出数据功能时,会用到这个模式。

这个模式会直接调用浏览器的下载功能弹出下载框或者调用默认的下载工具打开下载目录地址指定输入框。

output --- 该模式类似于frameset,会自动生成report document文件(预览report design文件),区别在于output不采用Ajax,而是将生成的报表内容直接输出到浏览器。不支持分页。

下面说说最主要的保留参数的含义:

“__report”  定义要预览的rptdesign文件路径,支持相对路径和绝对路径,相对路径是相对于web.xml中定义的工作目录。

“__document” 定义要预览的rptdocument文件路径,同样支持相对和绝对路径。相对路径是相对于web.xml中定义的工作目录。在同时定义了__report和__document参数时,以__document为优先,如未找到相应的document文件,才会从design文件生成document文件(frameset/output)或是直接去render这个design文件(preview/run)。

“__title”   定义报表显示的标题。

“__showtitle”  是否显示frameset模式下上方的标题部分。true | false

“__toolbar”   是否显示frameset模式下的工具条。true | false

“__navigationbar”  是否显示frameset模式下的导航条。true | false

“__parameterpage”  是否强制弹出或不弹出报表参数对话框。true | false

“__format”   输出报表的格式,默认为html。现在支持:pdf | doc | xls | postscript | ppt

“__locale”   设置Locale信息,如 __locale=zh_CN, 注意必须是国家加语言。

“__bookmark”   置页面要定位的书签名字。

“__page”       指定要输出的报表页数,这个依赖于报表的分页设计(page break)。

“__pagerange”  指定要输出的报表页数范围。如1,3,5-9。

“__clean”       BIRT里临时生成的一些文件都是和session相关的,比如临时document文件,还有image文件。这些文件也可以通过session进行管理,这个参数就是指定是否需要在session timeout的时候清除这些临时文件。默认值是true。 

Document文件夹用于缓存frameset的文档,session退了之后由系统自动删除,也可由用户删除文件夹,对程序不造成影响。

Logs文件夹用于生成系统出现错误时的日志文件。可以删除。

Report文件夹用于放置rptdesign文件,也可以放置在根目录,由url指定

Scriptlib文件夹用于放置用户自定义的脚本,也可以放置在根目录,由报表配置

WEB-INF文件夹用于配置报表运行时环境的各个参数,第二章已经有非常详细的描述,这儿强调一下JNDI的配置

1.tomcat配置jndi连接池

在 {tomcat目录}\webapps\{项目名}\WEB-INF 中新增context.xml文件,配置代码如下

  1. <?xml version="1.0" encoding="UTF-8"?><Context> <Resource auth="Container"   name="jdbc/travel_agency" type="javax.sql.DataSource" maxIdle="5" maxWait="-1" driverClassName="com.mysql.jdbc.Driver" username="itravel" password="709394" url="jdbc:mysql://192.168.1.100/travel_agency?useUnicode=true&characterEncoding=UTF-8" maxActive="10"/></Context>  

2.在web.xml中加入配置

  1. <resource-ref> <description>Database Source</description> <res-ref-name>jdbc/travel_agency</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth></resource-ref>  

如果weblogic已经配置了连接池(jdbc/myjndi),那么只需要在\{应用名}\WEB-INF 下新建context.xml,用于配置报表访问JNDI,内容如下:

  1. <resource-ref>  
  2. <description>Database Source</description>  
  3. <res-ref-name>jdbc/myjndi</res-ref-name>  
  4. <res-type>javax.sql.DataSource</res-type>  
  5. <res-auth>Container</res-auth>  
  6. </resource-ref>  

第二种工作模式jsp tag:

JSP birt tag的一个例子在第五章

  1. <birt:viewer id="birtViewer1"  
  2.                 reportDesign="orders.rptdesign"  
  3.                 baseURL="<%= request.getContextPath( )%>"  
  4.                 pattern="run"  
  5.                 height="367"  
  6.                 width="645"  
  7.                 format="html"  
  8.                 frameborder="false"  
  9.                 isHostPage="false"  
  10.                 isReportlet="true"  
  11.                 showParameterPage="false"  
  12.             >  
  13.             </birt:viewer>  

在\webapps\WebViewerExample\WEB-INF\tlds\birt.tld中有详细的定义。内容的一小部分如下文所示:

  1. <name>viewer</name>  
  2.         <tag-class>org.eclipse.birt.report.taglib.ViewerTag</tag-class>  
  3.         <body-content>JSP</body-content>  
  4.         <description>  
  5.             The viewer tag is to specify how to import and control BIRT Report Viewer into JSP page.  
  6.             This tag will use Ajax framework to retrieve report content.  
  7.         </description>  
  8.   
  9.         <attribute>  
  10.             <name>id</name>  
  11.             <required>true</required>  
  12.             <rtexprvalue>true</rtexprvalue>  
  13.             <description>  
  14.                 Specifies the current viewer id. It should be unique.  
  15.                 It can contain number,letter or underline.  
  16.             </description>              
  17.         </attribute>    
  18.   
  19.         <attribute>  
  20.             <name>pattern</name>  
  21.             <required>false</required>  
  22.             <rtexprvalue>true</rtexprvalue>  
  23.             <description>  
  24.                 Specifies which servlet pattern to be used to preview report.  
  25.                 Default value is frameset.  
  26.                 ( frameset or run )  
  27.             </description>  
  28.         </attribute>  

在此说明如下:

birt标签分为: viewer, report, param,parameterPage,paramDef这四个标签。

一、viewer标签

示例:

<birt:viewer  id="1"

             pattern="run"    

             reportDesign="test1.rptdesign"

             position="absolute"

             width="800"

             height="500"

             left="50"

             top="50"

             format="html"

             svg="false">

    <birt:param name="sample" value="abc"/>

    <birt:param name="Cust" value="<%=110%>"/>         

</birt:viewer>

id:  必须指定,

pattern: 不一定 要指定,指定运行使用的servlet, 默认为frameset

reportDesign:  指定报表文件名

title : 可选,指定报表的标题,其实这不是设计报表的标题,而是报表运行时显示在报表上面的标题。

isHostPage: 可选,默认为false,指定报表是否全屏显示,此属性设置,则width,height,scrolling 属性作废。

scrolling :可选,是否出现滚动条

position: 可选,报表相对于页面的位置,值为static | absolute | fixed | relative,如果设置了isHostPage,该属性作废。

style : 可选,报表显示的样式,没多说的。,如果设置了isHostPage,该属性作废

width,heigth,top,left: 分别设置报表显示的宽,高,上边距,左边距

frameborder :可选,设置报表所在的iframe是否显示边框,默认不显示。值为yes/no

reportDocument : 可选,指定报表文档,只支持file:url,这样的格式。

reportlet : 可选,使用reportDocument ,可指定这个属性,只是指定reportlet 实例的id, 另frameset不支持此属性。

bookmark : 可选,指定目标书签名称

locale : 指定Locale信息,指定语言环境

svg : 可选,指定是否支持输出svg格式文档。

format : 可选,指定报表的输出格式

pageOverflow : 可选,当输出格式为pdf时,指定页面溢出样式,0 表示自动,1表示实际大小,2表示适合页面的大小

pageNum: 可选,指定是否显示页码

pageRange:  指定页面范围。当运行文档文件时指定这个属性。

resourceFolder : 指定相关的资源文件,默认识别web.xml定义的资源文件夹。

showTitle: 是否显示报表标题,默认为true

showToolBar: 是否显示工具条,默认为true

showNavigationBar: 是否显示导航条,默认为true,但是如果allowPageBreak设置为false,该属性作废。

showParameterPage: 是否显示参数对话框。默认为true,

二、report标签

和view标签差不多,但是report没有使用ajax支持,而是直接将内容显示在页面。 内部应该使用了preview。

另有一个特别的属性reportContainer,有两个可选值,iframe,和div,默认为iframe. 指定使用report的容器。

其他属性和view都差不多。

<birt:report id="2"

             reportDesign="test.rptdesign"

             position="absolute"

             width="400"

             height="300"

             left="900"

             top="100"

             format="pdf"

             reportContainer="iframe">

    <birt:param name="sample" value="abc"/>         

</birt:report>    

三、param

报表参数相关的标签。

name: 指定报表参数名称

value; 参数值

pattern: 参数格式

displayText: 显示文字

isLocale: 指定参数是否本地化字符

四、parameterPage

配置参数页面。

id : 必选。指定参数页面的id

name : 指定参数页面name,如果isCustom设置为true,则此属性一定要写,且唯一。

isCustom : 指定是否使用用户自定义参数页面。默认为false;

target : 指定请求打开窗口的位置。

其他属性与view相似,给个例子:

<birt:parameterPage id="parameterPage"

                pattern="run"

                reportDesign="test.rptdesign"

                target="myiframe"

                width="600"

                height="400"

                format="html"/>

<iframe name="myiframe" width="600" height="400"></iframe>

五、paramDef

这个标签用来生成参数参数页面定义的参数的html代码。

有以下几个属性

id,name,value,pattern,displayText,isLocale,title,style,cssClass.

<birt:parameterPage

        id="report2" 

        name="page2"

        reportDesign="test.rptdesign"

        isCustom="true"                  //指定自定义页面

        pattern="frameset">

        id: <birt:paramDef id="id" name="id" title="这是设置id的区域"/>        

        <br><br>        

        

        sex: <birt:paramDef id="sex" name="sex"/>

        <br><br>        

        <input type="submit" name="submit" value="Sumbit form"/>

        <br><br>        

</birt:parameterPage>

假如你的text报表里有两个参数,一个参数为id,另一个参数为sex,这时候假如id是一列值,sex是checkbox.

那么这个参数页面就会把这个id要选择的值显示出来,把sex这个checkbox也显示出来。

第三种工作模式——在servlet或者java class中打开用报表设计器设计的报表,导出一个html,pdf或者其它格式的文档的输出到既定的目录;需要新建JAVA project或者java web project,导入report engine库,也就是birt-runtime-3_7_2\ReportEngine\lib目录下的包,如下:

为了便于大家理解,我把启动平台,打开报表,关闭平台分别放置在一个类的三个方法中,并做了相应的注释:

  1. package birt;  
  2. import org.eclipse.birt.core.framework.Platform;  
  3. import org.eclipse.birt.report.engine.api.EngineConfig;  
  4. import org.eclipse.birt.report.engine.api.HTMLRenderOption;  
  5. import org.eclipse.birt.report.engine.api.IReportEngine;  
  6. import org.eclipse.birt.report.engine.api.IReportEngineFactory;  
  7. import org.eclipse.birt.report.engine.api.IReportRunnable;  
  8. import org.eclipse.birt.report.engine.api.IRunAndRenderTask;  
  9. public class HtmlReport  
  10. {  
  11. IReportEngine engine=null;  
  12. EngineConfig config = null;  
  13.   
  14. HtmlReport ()  
  15. {  
  16. }  
  17. //用于运行报表  
  18. public void runReport()  
  19. {  
  20. try{  
  21. IReportRunnable design = null;  
  22. //Open the report design  
  23. design = engine.openReportDesign("d:\\CustomerOrdersFinal.rptdesign");  
  24. //Create task to run and render the report,  
  25. IRunAndRenderTask task = engine.createRunAndRenderTask(design);  
  26. HTMLRenderOption options = new HTMLRenderOption();  
  27. options.setOutputFileName("D:\\TEST.html");  
  28. options.setOutputFormat("html");  
  29. options.setEmbeddable(true);  
  30. task.setRenderOption(options);  
  31. task.run();  
  32. task.close();  
  33. }catch( Exception ex){  
  34. ex.printStackTrace();  
  35. }  
  36. }  
  37. //用于启动报表平台  
  38. public void startPlatform(){  
  39. try{  
  40. config = new EngineConfig( );  
  41. config.setBIRTHome("");//低版本的需要在此指定BIRT engine home地址  
  42. Platform.startup( config );  
  43. IReportEngineFactory factory = (IReportEngineFactory) Platform  
  44. .createFactoryObject( IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY );  
  45. engine = factory.createReportEngine( config );  
  46. }catch( Exception e){  
  47. e.printStackTrace();  
  48. }  
  49. }  
  50. //用于停止报表平台  
  51. public void stopPlatform(){  
  52. engine.destroy();  
  53. Platform.shutdown();  
  54. }  
  55. public static void main (String[] args)  
  56. {  
  57. HtmlReport html = new HtmlReport ();  
  58. html.startPlatform();  
  59. System.out.println("Started");  
  60. html.runReport();  
  61. html.stopPlatform();  
  62. System.out.println("Finished");  
  63. }  
  64. }  

其中已经设计好的报表布局如下:

运行报表,我们会在D盘下看到生成的TEST.html文件,打开内容如下:

第四种工作模式,扩展birt web viewer:

首先我们需要改写birt engine,内容如下:

  1. package birt;  
  2. import java.util.logging.Level;  
  3. import javax.servlet.ServletContext;  
  4. import org.eclipse.birt.core.exception.BirtException;  
  5. import org.eclipse.birt.core.framework.IPlatformContext;  
  6. import org.eclipse.birt.core.framework.Platform;  
  7. import org.eclipse.birt.core.framework.PlatformServletContext;  
  8. import org.eclipse.birt.report.engine.api.EngineConfig;  
  9. import org.eclipse.birt.report.engine.api.HTMLActionHandler;  
  10. import org.eclipse.birt.report.engine.api.HTMLEmitterConfig;  
  11. import org.eclipse.birt.report.engine.api.HTMLServerImageHandler;  
  12. import org.eclipse.birt.report.engine.api.IReportEngine;  
  13. import org.eclipse.birt.report.engine.api.IReportEngineFactory;  
  14.   
  15. public class BirtEngine {  
  16.     private static IReportEngine birtEngine = null;  
  17.     public static synchronized void initBirtConfig() {        
  18.     }  
  19.   
  20.     public static synchronized IReportEngine getBirtEngine(ServletContext sc) {       
  21.         EngineConfig config = new EngineConfig();  
  22.         config.setLogConfig(sc.getRealPath("\\logs"), Level.FINE);    
  23.         config.setEngineHome("");  
  24.         IPlatformContext context = new PlatformServletContext(sc);  
  25.         config.setPlatformContext(context);  
  26.           
  27.         //Register new image handler 解决了读取图片时的路径问题  
  28.         HTMLEmitterConfig emitterConfig = new HTMLEmitterConfig( );  
  29.         emitterConfig.setActionHandler( new HTMLActionHandler( ) );  
  30.         HTMLServerImageHandler imageHandler = new HTMLServerImageHandler( );  
  31.         emitterConfig.setImageHandler( imageHandler );  
  32.         config.getEmitterConfigs( ).put( "html", emitterConfig ); //-NLS-1$  
  33.   
  34.         try {  
  35.             Platform.startup(config);  
  36.         } catch (BirtException e) {  
  37.             e.printStackTrace();  
  38.         }  
  39.   
  40.         IReportEngineFactory factory = (IReportEngineFactory) Platform  
  41.                 .createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);  
  42.         birtEngine = factory.createReportEngine(config);  
  43.         return birtEngine;  
  44.     }  
  45.   
  46.     public static synchronized void destroyBirtEngine() {  
  47.         if (birtEngine == null) {  
  48.             return;  
  49.         }  
  50.         birtEngine.shutdown();  
  51.         Platform.shutdown();  
  52.         birtEngine = null;  
  53.     }  
  54.   
  55.     public Object clone() throws CloneNotSupportedException {  
  56.         throw new CloneNotSupportedException();  
  57.     }     
  58. }  

然后我们在servlet中调用这个自定义的birt engine;

  1. package birt;  
  2. import java.io.IOException;  
  3. import java.io.PrintWriter;  
  4. import java.util.ArrayList;  
  5. import java.util.Collection;  
  6. import java.util.Date;  
  7. import java.util.HashMap;  
  8. import java.util.Iterator;  
  9. import java.util.List;  
  10. import java.util.logging.Logger;  
  11.   
  12. import javax.servlet.ServletContext;  
  13. import javax.servlet.ServletException;  
  14. import javax.servlet.http.HttpServlet;  
  15. import javax.servlet.http.HttpServletRequest;  
  16. import javax.servlet.http.HttpServletResponse;  
  17.   
  18. import org.eclipse.birt.report.engine.api.EngineConstants;  
  19. import org.eclipse.birt.report.engine.api.HTMLRenderContext;  
  20. import org.eclipse.birt.report.engine.api.HTMLRenderOption;  
  21. import org.eclipse.birt.report.engine.api.IGetParameterDefinitionTask;  
  22. import org.eclipse.birt.report.engine.api.IParameterDefnBase;  
  23. import org.eclipse.birt.report.engine.api.IReportEngine;  
  24. import org.eclipse.birt.report.engine.api.IReportRunnable;  
  25. import org.eclipse.birt.report.engine.api.IRunAndRenderTask;  
  26. import org.eclipse.birt.report.engine.api.IScalarParameterDefn;  
  27.   
  28. public class birtServlet extends HttpServlet {  
  29.   
  30.       
  31.     private static final long serialVersionUID = 1L;  
  32.     private IReportEngine birtReportEngine = null;  
  33.     protected static Logger logger = Logger.getLogger("org.eclipse.birt");  
  34.   
  35.     public birtServlet () {  
  36.         super();  
  37.     }  
  38.   
  39.     public void destroy() {  
  40.         super.destroy();  
  41.         BirtEngine.destroyBirtEngine();  
  42.     }  
  43.   
  44.     public void doGet(HttpServletRequest req, HttpServletResponse resp)  
  45.             throws ServletException, IOException {  
  46.   
  47.         HashMap parmDetails = new HashMap();  
  48.   
  49.           
  50.         // get report name and launch the engine  
  51.         resp.setContentType("text/html");  
  52.         // resp.setContentType( "application/pdf" );  
  53.         // resp.setHeader ("Content-Disposition","inline; filename=test.pdf");  
  54.         //得到参数并放入paramsList集合  
  55.         String reportName = req.getParameter("ReportName");  
  56.         String bm = new String(req.getParameter("bm").getBytes("ISO8859_1"),"GB2312");  
  57.         String sj1 = req.getParameter("sj1");  
  58.         String sj2 = req.getParameter("sj2");  
  59.         List paramsList = new ArrayList();  
  60.         if (bm != null && !bm.equals("") && !bm.equals("null"))  
  61.             paramsList.add(bm);  
  62.         paramsList.add(sj1);  
  63.         paramsList.add(sj2);  
  64.           
  65.         ServletContext sc = req.getSession().getServletContext();  
  66.         this.birtReportEngine = BirtEngine.getBirtEngine(sc);  
  67.           
  68.         // 设置图片地址  
  69.         HTMLRenderContext renderContext = new HTMLRenderContext();  
  70.         renderContext.setBaseImageURL(req.getContextPath() + "\\report\\images");  
  71.         renderContext.setImageDirectory(sc.getRealPath("\\report\\images"));  
  72.   
  73.         //logger.log(Level.FINE, "image directory "  
  74.         //      + sc.getRealPath("\\report\\images"));  
  75.         //System.out.println(renderContext.getBaseImageURL());  
  76.         //System.out.println(renderContext.getImageDirectory());  
  77.   
  78.         HashMap<String, HTMLRenderContext> contextMap = new HashMap<String, HTMLRenderContext>();  
  79.         contextMap.put(EngineConstants.APPCONTEXT_HTML_RENDER_CONTEXT,  
  80.                 renderContext);  
  81.   
  82.         IReportRunnable design;  
  83.         try {  
  84.             // Open report design  
  85.             design = birtReportEngine.openReportDesign(sc  
  86.                     .getRealPath("")  
  87.                     + "\\" + reportName);  
  88.               
  89.             //以下是将报表里的参数和传递进来的参数匹配然后放到parmDetails集合中  
  90.             IGetParameterDefinitionTask taskParam = birtReportEngine.createGetParameterDefinitionTask( design );  
  91.             Collection params = taskParam.getParameterDefns( true );  
  92.   
  93.             Iterator iter = params.iterator();  
  94.             Iterator iterList = paramsList.iterator();  
  95.             // Iterate over all parameters  
  96.             while ( iter.hasNext() && iterList.hasNext() )  
  97.             {  
  98.                 IParameterDefnBase param = (IParameterDefnBase) iter.next( );  
  99.                 // Parameters are not in a group  
  100.                 IScalarParameterDefn scalar = (IScalarParameterDefn) param;  
  101.                 if(scalar.getName().equals("bm")){  
  102.                     String paramList = (String)iterList.next();  
  103.                     parmDetails.put( scalar.getName(),paramList);  
  104.                     //System.out.println(scalar.getName() + " " + paramList);  
  105.                 }else{  
  106.                     Date paramList = new Date();  
  107.                     parmDetails.put( scalar.getName(),paramList);  
  108.                     //System.out.println(scalar.getName() + " " + paramList);  
  109.                 }  
  110.             }  
  111.             taskParam.close();  
  112.             //  
  113.               
  114.             // create task to run and render report  
  115.             IRunAndRenderTask task = birtReportEngine  
  116.                     .createRunAndRenderTask(design);  
  117.             task.setAppContext(contextMap);  
  118.             task.setParameterValues(parmDetails);  
  119.   
  120.             // set output options  
  121.             HTMLRenderOption options = new HTMLRenderOption();  
  122.             options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_HTML);  
  123.             // options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_PDF);  
  124.             options.setOutputStream(resp.getOutputStream());  
  125.             task.setRenderOption(options);  
  126.   
  127.             // 运行报表  
  128.             task.run();  
  129.             task.close();  
  130.         } catch (Exception e) {  
  131.   
  132.             e.printStackTrace();  
  133.             throw new ServletException(e);  
  134.         }  
  135.     }  
  136.   
  137.     public void doPost(HttpServletRequest request, HttpServletResponse response)  
  138.             throws ServletException, IOException {  
  139.           
  140.     }  
  141.   
  142.     public void init() throws ServletException {  
  143.     }  
  144. }  

最后,配置birt engine的访问地址,在web.xml中配置如下:

  1. <servlet>  
  2.         <servlet-name>birtServlet </servlet-name>  
  3.         <servlet-class>birt.birtServlet</servlet-class>  
  4.     </servlet>  
  5.       
  6.     <servlet-mapping>  
  7.         <servlet-name>birtServlet </servlet-name>  
  8.         <url-pattern>/myBirtFrame</url-pattern>  
  9.     </servlet-mapping>  

这样,我们可以以这样的方式访问自己的birt viewer:

http://localhost:8080/birt/myBirtFrame?ReportName=CustomerOrdersFinal.rptdesign

注意:如果是在linux或者unix环境运行,则以上地址的”\\”都必须改成”/”,windows和linux的区别,大家都懂的。

以上参数的访问方式也是需要完善的,后面的章节会详细讲解如何扩展birt web viewer。

第五种方式,运用报表设计API产生报表,运行并输出报表。

下面是一个简单的案例

  1. package birt;  
  2. import java.io.IOException;  
  3. import org.eclipse.birt.core.framework.Platform;  
  4. import org.eclipse.birt.report.model.api.CellHandle;  
  5. import org.eclipse.birt.report.model.api.DesignConfig;  
  6. import org.eclipse.birt.report.model.api.DesignElementHandle;  
  7. import org.eclipse.birt.report.model.api.ElementFactory;  
  8. import org.eclipse.birt.report.model.api.GridHandle;  
  9. import org.eclipse.birt.report.model.api.IDesignEngine;  
  10. import org.eclipse.birt.report.model.api.IDesignEngineFactory;  
  11. import org.eclipse.birt.report.model.api.ImageHandle;  
  12. import org.eclipse.birt.report.model.api.LabelHandle;  
  13. import org.eclipse.birt.report.model.api.ReportDesignHandle;  
  14. import org.eclipse.birt.report.model.api.RowHandle;  
  15. import org.eclipse.birt.report.model.api.SessionHandle;  
  16. import org.eclipse.birt.report.model.api.activity.SemanticException;   
  17. import com.ibm.icu.util.ULocale;  
  18. public class SimpleCreate {   
  19.   
  20.        public static void main( String[] args )  
  21.        {  
  22.            try  
  23.            {  
  24.                buildReport( );  
  25.            }  
  26.            catch( IOException e )  
  27.            {  
  28.                e.printStackTrace();  
  29.            }  
  30.            catch( SemanticException e )  
  31.            {  
  32.                e.printStackTrace();  
  33.            }  
  34.        }  
  35.           
  36.        // This method shows how to build a very simple BIRT report with a  
  37.        // minimal set of content: a simple grid with an image and a label.  
  38.           
  39.        static void buildReport() throws IOException, SemanticException  
  40.        {  
  41.            // Create a session handle. This is used to manage all open designs.  
  42.            // Your app need create the session only once.  
  43.               
  44.            //Configure the Engine and start the Platform   
  45.            DesignConfig config = new DesignConfig( );  
  46.   
  47.            config.setProperty("BIRT_HOME", "E:\\birt汉化包\\birt-runtime-3_7_2\\ReportEngine");  
  48.            IDesignEngine engine = null;  
  49.            try  
  50.            {  
  51.                Platform.startup( config );  
  52.                IDesignEngineFactory factory = (IDesignEngineFactory) Platform.createFactoryObject( IDesignEngineFactory.EXTENSION_DESIGN_ENGINE_FACTORY );  
  53.                engine = factory.createDesignEngine( config );  
  54.            }  
  55.            catch( Exception ex )  
  56.            {  
  57.                ex.printStackTrace();  
  58.            }          
  59.                       
  60.            SessionHandle session = engine.newSessionHandle( ULocale.ENGLISH ) ;  
  61.               
  62.            // Create a new report design.  
  63.            ReportDesignHandle design = session.createDesign( );  
  64.               
  65.            // The element factory creates instances of the various BIRT elements.  
  66.            ElementFactory efactory = design.getElementFactory( );  
  67.               
  68.            // Create a simple master page that describes how the report will appear when printed.  
  69.            //  
  70.            // Note: The report will fail to load in the BIRT designer unless you create a master page.  
  71.            DesignElementHandle element = efactory.newSimpleMasterPage( "Page Master" );   
  72.            design.getMasterPages( ).add( element );  
  73.               
  74.            // Create a grid and add it to the "body" slot of the report design.  
  75.            GridHandle grid = efactory.newGridItem( null, 2 /* cols */, 1 /* row */ );  
  76.         design.getBody( ).add( grid );  
  77.               
  78.            // Note: Set the table width to 100% to prevent the label  
  79.            // from appearing too narrow in the layout view.  
  80.            grid.setWidth( "100%" );   
  81.               
  82.            // Get the first row.  
  83.            RowHandle row = (RowHandle) grid.getRows( ).get( 0 );  
  84.               
  85.            // Create an image and add it to the first cell.  
  86.            ImageHandle image = efactory.newImage( null );  
  87.            CellHandle cell = (CellHandle) row.getCells( ).get( 0 );  
  88.            cell.getContent( ).add( image );  
  89.      image.setURL( "\"https://img-my.youkuaiyun.com/uploads/201301/09/1357690895_3463.png\"" );   
  90.               
  91.            // Create a label and add it to the second cell.  
  92.            LabelHandle label = efactory.newLabel( null );  
  93.            cell = (CellHandle) row.getCells( ).get( 1 );  
  94.            cell.getContent( ).add( label );  
  95.            label.setText( "Hello, world!" );   
  96.               
  97.            // Save the design and close it.  
  98.            design.saveAs( "d:\\sample.rptdesign" );   
  99.            design.close( );  
  100.            System.out.println("Finished");  
  101.               
  102.            // We're done!  
  103.        }  
  104.     }   

运行,我们即可在D盘看到sample.rptdesign

在设计器中预览这个报表,我们看到:

打开并展示报表见第三种报表运行模式,后面章节会更详细的讲解如何运用报表API生成报表设计文件,并运行产生输出。

 

第七章 BIRT分组报表 7.1 分组的建立,插入,删除 我们先构建报表,空白模板,示例数据库和sql查询数据源,数据集setOrders,如下 select CLASSICMODELS.CUSTOMERS.CUSTOMERNAME, CLASSICMODELS.ORDERS.ORDERNUMBER, CLASSICMODELS.ORDERS.ORDERDATE, CLASSICMODELS.ORDERS.ST 阅读详情

相关推荐

BIRT报表目录

打算近期出版一本全面介绍BIRT使用的书籍,能够帮助大家全面了解BIRT的方方面面,用丰富的案例和源码,例子,诠释这个报表设计工具,展现工具,开源框架,扩展框架的种种优点特性。 初稿内容如下,书写正在进行中~ 欢迎大家光临我的主页:http://blog.youkuaiyun.com/birtbird~ BIRT的世界-BIRT技术漫谈 目录 第一章 BIRT简介 3 1.1 BIR

BIRT的世界-BIRT技术漫谈 1万+

BIRT报表使用

BIRT是一个开源软件项目,它提供BIRT技术平台来创建数据可视化和报表,这些可视化和报表可以嵌入到丰富的客户端和Web应用程序中,尤其是那些基于Java和Java EE的应用程序。 内含下载地址

乱域葬魂 4167

Eclipse报表插件birt

1. BIRT 概述<br />BIRT是一个Eclipse-based开放源代码报表系统。它主要是用在基于Java与J2EE的Web应用程序上。BIRT主要由两部分组成:一个是基于Eclipse的报表设计和一个可以加到你应用服务的运行期组件。BIRT同时也提供一个图形报表制作引擎。<br />    使用BIRT,能制作出多样化的报表到你的应用中。比如:列表 lists ,图表 charts,混合报表 Compound Reports,交叉表(二维表)Crosstabs(二维报表目前在BIRT 2.1.1

soundyrose的专栏 7025

【birt】报表工具

一、概念 BIRT报表工具是一个开源的、基于Eclipse的报表生成工具,专门用于为企业应用生成各种格式的报表。它能够帮助开发人员在Java应用中嵌入报告和数据分析功能,提供丰富的报表设计、数据集成和视图呈现能力。BIRT广泛应用于企业的数据报告、业务智能、图表可视化等领域。 能够从各种数据源(如数据库、Web服务、XML、CSV等)获取数据,并基于这些数据生成图表、报表、仪表板等多种数据可视化形式。其核心功能包括报表设计、数据集成、图表生成、定制报表输出等。 二、BIRT由两部分组成 先设计,再运行 B

weixin_44919491的博客 2227

精通BIRT:Eclipse商务智能报表工具开发实践指南

书籍正有清华大学出版社编辑出版发行中,敬请期待,目录如下:  第一章 BIRT简介 5 1.1 BIRT初识 5 1.2 BIRT安装 8 1.2.1 BIRT设计器的安装 8 1.2.2 BIRT运行时环境的安装 9 第二章 BIRT设计器概述及本地化支持 12 2.1 BIRT设计器概述 12 2.1.1 基本概念 12 2.1.2 基本视图 13 2.2 BIRT本地化之

BIRT的世界-BIRT技术漫谈 1万+

odoo15 report 标签弃用

warnings.warn(f"The <report> tag is deprecated, use a <record> tag for {xml_id!r}.", DeprecationWarning)

fqfq123456的专栏 464

第十二章 BIRT报表的部署与配置(续) .

12.2 BIRT报表的打印和导出 birt报表在打印和导出的时候,如果出现中文字符,有可能会出现文字丢失空白,或者pdf缺少相应字体,或者直接乱码的问题,这个现象非常普遍和复杂。这是一个和环境密切相关的配置,由于中文字体涉及到很多的地方配置,主要包括五个方面,报表设计时候的字体配置,runtime的page css的配置,runtime的fontconfig的配置,linux环境的字体配置,a

huazaichang的专栏 2188

利用Eclipse和BIRT开发交互式Web报表程序

本文还有配套的精品资源,点击获取 简介:Eclipse是流行的Java集成开发环境,BIRT插件则为Eclipse增加了数据可视化和报表开发的功能。安装BIRT插件后,开发者可以在Eclipse中创建BIRT Web项目,设计交互式报表,并通过Servlet与多种数据库连接,实现数据的动态展示。BIRT报表支持多种输出格式,并能与Eclipse的版本管理及团队协作工具集成,...

weixin_42588555的博客 1751

开源报表birt

开源报表BIRT开发手册       目  录   1     Birt介绍...5 1.1      报表介绍... 5 1.2      基本概念... 5 1.3    丰富的报表... 5 1.4    BIRT报表由四部分组成... 6 1.5    报表设计器... 6 2     Birt插件安装...8 2.1      插件版本说明

1万+

BIRT运行时环境4.7版:报表部署与执行指南

BIRT(Business Intelligence and Reporting Tools)是一个开源的报表系统,旨在帮助开发者和最终用户创建基于Web的报表。BIRT项目提供了丰富的报表设计工具和一个强大的报表引擎,从而使得用户能够根据数据源生成各类报表。BIRT项目不仅支持传统的报表功能,比如表格和图表的展示,还具备了强大的数据源兼容性,这使得其可以广泛地应用在各种IT环境中。BIRT项目的发展和壮大,使其成为企业级报表解决方案的首选。

weixin_28771751的博客 797

STM32F103C8T6实战:手把手教你搭建智能火灾报警系统(附MQ-2传感器调试技巧)

本文详细介绍了基于STM32F103C8T6单片机和MQ-2烟雾传感器的智能火灾报警系统搭建过程。从硬件选型、电路设计到软件开发,提供全面的实战指导,特别包含MQ-2传感器调试技巧,帮助开发者快速实现稳定可靠的智能火灾监控系统。

year5的博客 213

十二、BIRT报表的部署与配置

12.1 报表的工作模式以及相应的部署和配置 虽然为了示例的需要,在前文的第二章讲过BIRT的配置,以及在文本类报表,网格报表,图表中用过birt jsp tag,也做过一些说明。但报表的工作模式,不仅仅包含这两种。实际上,BIRT有五种工作模式, 第一种是用jsp或者javascript访问url,这个url遵循特定的格式,例如url/frameset?__report=&a...

weixin_41961329的博客 2514

【重启后nvidia-smi 命令出现错误】

NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make sure that the latest NVIDIA driver is installed and running.

qq_44769377的博客 5211

Birt与MyEclipse的集成及Birt的安装部署问题

BIRT是一个Eclipse-based开放源代码报表系统。它主要是用在基于Java与J2EE的Web应用程序上。BIRT主要由两部分组成:一个是基于Eclipse的报表设计和一个可以加到你应用服务的运行期组件。BIRT同时也提供一个图形报表制作引擎。 BIRT拥有和Dreamweaver一般的操作界面,可以像画table一样画报表,也可以生成图片、导出Excel、html分页,样式比script

Hello World! 7851

用OpenNI2获取奥比中光Astra Pro及 Astra Pro SM输出的深度图(win,linux arm64 x64平台)

搞了一个奥比中光Astra Pro,想在windows平台,和linux rk3588 上获取深度信息,之前的驱动下载已经不好用了。

babytiger的专栏 1305

走马观碑组智能车竞赛:目标板识别算法优化与实战技巧(基于OpenCV)

本文针对智能车竞赛走马观碑组别的核心挑战,深入探讨了基于OpenCV的目标板识别算法优化与实战技巧。文章系统分析了PVC赛道环境下的光照、运动模糊等干扰因素,详细拆解了从红色矩形定位、透视校正到特征提取与分类的完整流程,并提供了工程优化、速度提升及现场调试的实用策略,旨在帮助参赛队伍构建一套在高速运动中既准又快的鲁棒识别系统。

life6的博客 732

birt报表开发-04,birt项目部署

1、首先下载birt-runtime,这个版本一定要和eclipse,birt的版本一致否者就会出现 There is no report design object available.异常 详见: birt报表报错, There is no report design object available.org.eclipse.birt.report.exception.ViewerExce...

登峰小蚁 6669

让 Claude Code 接管 SAP 事务流, 用 Python 和 SAP GUI Scripting 做一个真正能干活的 AI Agent

摘要:SAP系统自动化面临的核心瓶颈在于繁琐的GUI操作而非分析能力不足。通过整合Claude AI、Python和SAP GUI Scripting技术,可构建能直接操作SAP界面的智能代理。该方案利用SAP官方提供的脚本接口,实现事务码执行、界面导航、数据提取等自动化操作,特别适用于DMLT过账引擎等复杂错误分析场景。相比传统SQL导出方案,这种GUI级自动化能处理树控件、ALV表格等复杂界面元素,且无需额外API开发,直接在现有SAP GUI会话上工作,在保持原有权限体系的同时显著提升效率。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 321
上一篇: 第十一章 BIRT数据绑定与脚本,事件机制详解
下一篇: 第十三章 BIRT报表引擎API及报表API
freedom1993
博客等级 码龄12年 25粉丝 57原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值