pentaho report 发布

最近看了pentaho report 这个东东?本人下载的3.8 pdi

1方式 发布的时候是直接发布到pentaho  BI SERVER的。 BI SERVER东东太大。
2方式,报表引擎嵌入项目中()
刚刚开始接触这块,想请教一下,如果想把这款内容单独插入项目中,该如何进行呢。E文水平有限。
后来到一个Pentaho.Reporting.3.5.for.Java.Developers.pdf 有一个章节
(Embedding your report in an enterprise web application) 感悟 了。
1、我先将必须的LIB 放到J2EEWEB lib下。

2.web.xml 配置
3、Servlet代码如下
4.启动项目 访问 基本成功,只是报表调用JNDI, 调用报错 这需要配置一下。
5.还在继续研究  。。。
Servlet代码:
mport java.io.IOException;
import java.net.URL;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.pentaho.reporting.engine.classic.core.ClassicEngineBoot;
import org.pentaho.reporting.engine.classic.core.MasterReport;
import org.pentaho.reporting.engine.classic.core.ReportProcessingException;
import org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.PdfReportUtil;
import org.pentaho.reporting.engine.classic.core.modules.output.table.html.HtmlReportUtil;
import org.pentaho.reporting.engine.classic.core.modules.output.table.rtf.RTFReportUtil;
import org.pentaho.reporting.engine.classic.core.modules.output.table.xls.ExcelReportUtil;
import org.pentaho.reporting.libraries.resourceloader.Resource;
import org.pentaho.reporting.libraries.resourceloader.ResourceException;
import org.pentaho.reporting.libraries.resourceloader.ResourceManager;

public class MyReport extends HttpServlet {
@Override
public void init() throws ServletException {
// TODO Auto-generated method stub
super.init();
ClassicEngineBoot.getInstance().start();
}

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
super.doGet(req, resp);
try { 
// load report definition
ResourceManager manager = new ResourceManager();
manager.registerDefaults();
String reportPath = "file:"+this.getServletContext().getRealPath(
"report/Multi_Pie_Chart.prpt");
Resource res = manager.createDirectly(new URL(reportPath),
MasterReport.class);
MasterReport report = (MasterReport) res.getResource();
String outputFormat = req.getParameter("outputFormat");
if("pdf".equals(outputFormat)) {
// render in pdf
resp.setContentType("application/pdf");
PdfReportUtil.createPDF(report, resp.getOutputStream());
} else if ("pdf".equals(outputFormat)) {
// render in pdf
resp.setContentType("application/pdf");
PdfReportUtil.createPDF(report, resp.getOutputStream());
} else if ("xls".equals(outputFormat)) {
// render in excel
resp.setContentType("application/vnd.ms-excel");
ExcelReportUtil.createXLS(report, resp.getOutputStream());
} else {

HtmlReportUtil.createStreamHTML(report, resp.getOutputStream());
}
} catch (ResourceException e) {
e.printStackTrace();
} catch (ReportProcessingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
super.doPost(req, resp);
}

}

你可能感兴趣的:(Web,.net,xml,servlet,Excel)