标签:pentaho report 教程 集成 webapp servlet
Pentaho Report Designer 入门教程(三)
采用Pentaho Report Designer5.1版本,也是最新的版本。
一、 安装和介绍
介绍部分内容略,首先安装jdk,并配置java相关环境变量,下载pentaho report并解压,直接运行即可。
二、 第一个示例
三、在Swing程序中集成
四、在j2ee程序中集成
? 新建web项目
? 编写ant脚本,编译运行项目
<?xml version="1.0"encoding="UTF-8" standalone="no"?>
<projectbasedir="."default="start_tomcat"name="Ch2WebApp">
<propertyname="webDir"value="war"/>
<propertyname="tomcat.home"value="D:/program/tomcat6"/>
<pathid="classpath">
<filesetdir="lib">
<includename="*.jar"/>
</fileset>
<filesetfile="${tomcat.home}/lib/servlet-api.jar"/>
</path>
<pathid="runtime_classpath">
<filesetdir="lib">
<includename="*.jar"/>
</fileset>
<dirsetdir="classes"/>
</path>
<targetname="compile">
<echomessage="compile"/>
<mkdirdir="classes"/>
<javacclasspathref="classpath"destdir="classes"srcdir="src"includeantruntime="on"fork="true"encoding="UTF-8"/>
</target>
<targetname="war"depends="compile">
<deletefile="chapter2.war"/>
<warbasedir="war"destfile="chapter2.war"webxml="war/WEB-INF/web.xml">
<classesdir="classes"/>
<zipfilesetdir="data"prefix="data"/>
<zipfilesetdir="lib"prefix="WEB-INF/lib"/>
</war>
<deletedir="${tomcat.home}/webapps/chapter2"/>
<deletefile="${tomcat.home}/webapps/chapter2.war"/>
<copyfile="chapter2.war"todir="${tomcat.home}/webapps"/>
</target>
<targetname="start_tomcat"depends="war">
<exectimeout="1000"dir="${tomcat.home}/bin"executable="${tomcat.home}/bin/shutdown.bat"/>
<sleepseconds="2"/>
<execdir="${tomcat.home}/bin"executable="${tomcat.home}/bin/startup.bat"/>
</target>
</project>
? 测试通过servlet 访问不同文件格式的报表
publicvoid init(ServletConfig config)throws ServletException {
ClassicEngineBoot.getInstance().start();
super.init(config);
}
protectedvoiddoGet(HttpServletRequest request,
HttpServletResponse response)throws ServletException, IOException {
try {
ResourceManager manager =new ResourceManager();
manager.registerDefaults();
String reportPath = "file:"
+ this.getServletContext().getRealPath(
"data/ch2_1.prpt");
Resource res =manager.createDirectly(newURL(reportPath),
MasterReport.class);
MasterReport report = (MasterReport)res.getResource();
// determine the output format and renderaccordingly
String outputFormat =request.getParameter("outputFormat");
if ("pdf".equals(outputFormat)) {
// render thepdf
response.setContentType("application/pdf");
PdfReportUtil.createPDF(report,response.getOutputStream());
} elseif ("xls".equals(outputFormat)) {
// render in excel
response.setContentType("application/vnd.ms-excel");
ExcelReportUtil.createXLS(report,response.getOutputStream());
} elseif ("rtf".equals(outputFormat)) {
// render inrtf
response.setContentType("application/rtf");
RTFReportUtil.createRTF(report,response.getOutputStream());
}
} catch (Exception e) {
e.printStackTrace();
}
super.doGet(request, response);
}
? jsp或html文件调用servlet
<body>
<h1>Example Application</h1>
<p>This is an exampleapplication demonstrating how to embed
Pentaho Reporting into yourweb application.</p>
<a href="report?outputFormat=pdf"target="black">Generate PDF Report </a><br/>
<a href="report?outputFormat=xls"target="black">Generate Excel Report</a><br/>
<a href="report?outputFormat=rtf"target="black">Generate RTF Report </a><br/>
</body>
Pentaho Report Designer 入门教程(三)
标签:pentaho report 教程 集成 webapp servlet
原文地址:http://blog.csdn.net/neweastsun/article/details/39575425