if you do not want to have the server pentaho running to do this, you can make a servlet that the output is the contents of a report in html, pdf, ect., this can be accomplished using libraries pentaho report designer the can found within the same tool, first you design the report and then run it in the servlet that you created, passed as a parameter the location, the type of output, and additional parameters you define in the report
import session.ReportSession;
public class ServletReport extends HttpServlet {
public ServletReport() {
}
public void init() {
ClassicEngineBoot.getInstance().start();
}
protected void doGet(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException,
IOException {
generateReport(req, resp);
}
protected void doGet(HttpServletRequest req,
HttpServletResponse resp) throws ServletException,
IOException {
generateReport(req, resp);
}
protected void doPost(HttpServletRequest req,
HttpServletResponse resp) throws ServletException,
IOException {
generateReport(req, resp);
}
private void generateReport(HttpServletRequest req,
HttpServletResponse resp) throws ServletException,
IOException {
HttpSession session = req.getSession(true);
ReportSession values =
(ReportSession)session.getAttribute("ReportSession");
// URL reportDefinitionURL = values.getReportDefinitionURL();
String reportPath = req.getParameter("Report");
String contenType = (String)req.getParameter("ContenType");
//String isMDX = (String)req.getParameter("MDX");
String url =
req.getRequestURL().substring(0, req.getRequestURL().indexOf("servletreport")) +
"Reportes/";
URL reportDefinitionURL = new URL(url + reportPath);
MasterReport report = createReportDefinition(reportDefinitionURL);
try {
//report.setQ
Map<String, Object> reportParameters =
values.getReportParameters();
if (null != reportParameters) {
for (String key : reportParameters.keySet()) {
report.getParameterValues().put(key,
(Object)reportParameters.get(key));
}
}
} catch (Exception e) {
// TODO: Add catch code
e.printStackTrace();
}
OutputStream out = resp.getOutputStream();
try {
if (contenType.equalsIgnoreCase("HTML")) {
resp.setContentType("text/html; charset=\"UTF-8\"");
HtmlReportUtil.createStreamHTML(report, out);
} else if (contenType.equalsIgnoreCase("PDF")) {
resp.setContentType("application/pdf");
PdfReportUtil.createPDF(report, out);
} else if (contenType.equalsIgnoreCase("EXCEL")) {
resp.setContentType("application/vnd.ms-excel");
ExcelReportUtil.createXLS(report, out);
} else if (contenType.equalsIgnoreCase("RTF")) {
resp.setContentType("application/rtf");
RTFReportUtil.createRTF(report, out);
}
} catch (ReportProcessingException rpe) {
rpe.printStackTrace();
} finally {
out.close();
}
}
//Return a value using EL
private Object executeValueExpression(String valueExpression) {
FacesContext fctx = FacesContext.getCurrentInstance();
ELContext elctx = fctx.getELContext();
Application app = fctx.getApplication();
ExpressionFactory exprFactory = app.getExpressionFactory();
ValueExpression valueExpr =
exprFactory.createValueExpression(elctx, valueExpression,
Object.class);
return valueExpr.getValue(elctx);
}
private MasterReport createReportDefinition(URL reportDefinitionURL) throws MalformedURLException {
try {
ResourceManager resourceManager = new ResourceManager();
resourceManager.registerDefaults();
Resource directly =
resourceManager.createDirectly(reportDefinitionURL,
MasterReport.class);
MasterReport report = (MasterReport)directly.getResource();
return report;
} catch (ResourceException e) {
e.printStackTrace();
}
return null;
}
}