本教程介绍了在Java报表工具中运行Web查看器的基础知识。例如,在网页上显示带有仪表板的报表。
首先,我们需要创建动态Web项目。
接下来将Stimulsoft Java Libs添加到项目中。
您还可以转换为Maven项目并配置pom.xml文件以使用Maven中的库。
4.0.0 webviewer webviewer 0.0.1-SNAPSHOT war src maven-compiler-plugin 3.5.1 1.6 1.6 com.stimulsoft stimulsoft-reports-libs 2017.1.1
接下来,我们需要在WebContent / WEB-INF文件夹中创建web.xml文件。在这里,我们配置了StimulsoftResource servlet,它检索诸如* .js和图像文件之类的内容,以及使用java web查看器操作的StiWebViewerActionServlet。
stimulsoft_webviewer index.jsp StimulsoftResource com.stimulsoft.web.servlet.StiWebResourceServlet StimulsoftResource /stimulsoft_web_resource/* StimulsoftAction com.stimulsoft.webviewer.servlet.StiWebViewerActionServlet StimulsoftAction /stimulsoft_webviewer_action
在下一步中,我们需要在WebContent文件夹中创建index.jsp页面。在这里,我们加载Dashboards.mrt报告模板文件并呈现报表。我们还可以配置Web查看器,例如将背景颜色设置为灰色。最后,将Web查看器标记放到jsp页面。
<%@page import=";com.stimulsoft.base.drawing.StiColorEnum"%><%@page import=";com.stimulsoft.base.drawing.StiColor"%><%@page import=";com.stimulsoft.webviewer.StiWebViewerOptions"%><%@page import=";com.stimulsoft.webviewer.StiWebViewer"%><%@page import=";java.io.File"%><%@page import=";com.stimulsoft.report.StiSerializeManager"%><%@page import=";com.stimulsoft.report.StiReport"%><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ taglib uri="http://stimulsoft.com/webviewer" prefix="stiwebviewer"%>Stimulsoft Reports for Java <% StiReport report = StiSerializeManager.deserializeReport( new File(request.getSession().getServletContext().getRealPath("/reports/Dashboards.mrt"))); report.render(); StiWebViewerOptions options = new StiWebViewerOptions(); options.getAppearance().setBackgroundColor(StiColorEnum.Gray.color()); pageContext.setAttribute("report", report); pageContext.setAttribute("options", options); %>
现在,您可以将项目部署到Tomcat并运行它。
在下面的屏幕截图中,您可以看到示例代码的结果。