翻譯|使用教程|編輯:李顯亮|2021-08-31 10:08:41.140|閱讀 288 次
概述:本教程展示了在 Java 報告工具中運行 Web 設計器的基礎知識。例如,打開以編輯主從報告模板。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Stimulsoft Ultimate是用于創建報表和儀表板的通用工具集。該產品包括用于WinForms、ASP.NET、.NET Core、JavaScript、WPF、PHP、Java和其他環境的完整工具集。
Stimulsoft Reports不僅擁有強大的報表導出系統,而且還支持多種報表導出格式,擁有簡單且強大的報表引擎。Stimulsoft Reports基本原則是,用簡單常規的方法創建報表,將不同的技術應用于應用程序。Stimulsoft Reports.Java是一個專為在Java應用程序中的報表進行交互和處理的報表工具。
點擊下載Stimulsoft Reports.Java v2021.3.1最新版
本教程展示了在 Java 報告工具中運行 Web 設計器的基礎知識。例如,打開以編輯主從報告模板。
首先,我們需要創建動態 Web 項目。
然后將 Stimulsoft Java Libs 添加到項目中。
也可以轉換為 Maven 項目并配置pom.xml文件以使用來自Maven 的庫:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 //maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>webdesigner</groupId> <artifactId>webdesigner</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <build> <sourceDirectory>src</sourceDirectory> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>com.stimulsoft</groupId> <artifactId>stimulsoft-reports-libs</artifactId> <version>2017.1.1</version> </dependency> </dependencies> </project>
接下來,我們需要在“WebContent/WEB-INF”文件夾中創建“web.xml”文件。這里我們配置了StimulsoftResourceservlet 來檢索諸如 *.js 和圖像文件等內容,以及StiWebDesignerActionServlet與 java web 設計器一起操作的servlet :
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/webapp_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee //java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>stimulsoft_webdesigner</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>StimulsoftResource</servlet-name> <servlet-class>com.stimulsoft.web.servlet.StiWebResourceServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>StimulsoftResource</servlet-name> <url-pattern>/stimulsoft_web_resource/*</url-pattern> </servlet-mapping> <servlet> <servlet-name>StimulsoftDesignerAction</servlet-name> <servlet-class>com.stimulsoft.webdesigner.servlet.StiWebDesignerActionServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>StimulsoftDesignerAction</servlet-name> <url-pattern>/stimulsoft_webdesigner_action</url-pattern> </servlet-mapping> </web-app>
在下一步中,我們需要在“WebContent”文件夾中創建“index.jsp”頁面。這里我們加載“Master-Detail.mrt”報告模板文件并定義報告的數據路徑:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <%@page import=";java.io.FileOutputStream"%> <%@page import=";java.io.FileInputStream"%> <%@page import=";com.stimulsoft.report.utils.data.StiDataColumnsUtil"%> <%@page import=";com.stimulsoft.report.dictionary.StiDataColumnsCollection"%> <%@page import=";com.stimulsoft.report.dictionary.StiDataColumn"%> <%@page import=";com.stimulsoft.report.utils.data.StiSqlField"%> <%@page import=";com.stimulsoft.report.dictionary.dataSources.StiDataTableSource"%> <%@page import=";com.stimulsoft.report.utils.data.StiXmlTable"%> <%@page import=";com.stimulsoft.report.utils.data.StiXmlTableFildsRequest"%> <%@page import=";com.stimulsoft.webdesigner.StiWebDesigerHandler"%> <%@page import=";com.stimulsoft.webdesigner.StiWebDesignerOptions"%> <%@page import="com.stimulsoft.report.dictionary.databases.StiXmlDatabase"%> <%@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=";//stimulsoft.com/webdesigner" prefix="stiwebdesigner"%> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Stimulsoft Webdesigner for Java</title> <style type="text/css"> </style> </head> <body> <% final String reportPath = request.getSession().getServletContext().getRealPath("/reports/Master-Detail.mrt"); final String xmlPath = request.getSession().getServletContext().getRealPath("/data/Demo.xml"); final String xsdPath = request.getSession().getServletContext().getRealPath("/data/Demo.xsd"); final String savePath = request.getSession().getServletContext().getRealPath("/save/"); ...
接下來我們需要實現StiWebDesigerHandler用于填充報告數據并保存/加載報告模板:
... StiWebDesignerOptions options = new StiWebDesignerOptions(); //options.setLocalization(request.getSession().getServletContext().getRealPath("/localization/de.xml")); ...
我們也可以指定網頁設計器選項,例如設置必要的本地化:
... StiWebDesigerHandler handler = new StiWebDesigerHandler() { // Occurred on loading webdesinger. Must return edited StiReport public StiReport getEditedReport(HttpServletRequest request) { try { StiReport report = StiSerializeManager.deserializeReport(new File(reportPath)); report.getDictionary().getDatabases().add(new StiXmlDatabase("Demo", xsdPath, xmlPath)); return report; } catch (Exception e) { e.printStackTrace(); } return null; } // Occurred on opening StiReport. Method intended for populate report data. public void onOpenReportTemplate(StiReport report, HttpServletRequest request) { report.getDictionary().getDatabases().add(new StiXmlDatabase("Demo", xsdPath, xmlPath)); } // Occurred on new StiReport. Method intended for populate report data. public void onNewReportTemplate(StiReport report, HttpServletRequest request) { report.getDictionary().getDatabases().add(new StiXmlDatabase("Demo", xsdPath, xmlPath)); try { StiXmlTableFildsRequest tables = StiDataColumnsUtil.parceXSDSchema(new FileInputStream(xsdPath)); for (StiXmlTable table : tables.getTables()) { StiDataTableSource tableSource = new StiDataTableSource( "Demo." + table.getName(), table.getName(), table.getName()); tableSource.setColumns(new StiDataColumnsCollection()); for (StiSqlField field : table.getColumns()) { StiDataColumn column = new StiDataColumn( field.getName(), field.getName(), field.getSystemType()); tableSource.getColumns().add(column); } tableSource.setDictionary(report.getDictionary()); report.getDictionary().getDataSources().add(tableSource); } } catch (Exception e) { e.printStackTrace(); } } // Occurred on save StiReport. Method must implement saving StiReport public void onSaveReportTemplate(StiReport report, StiRequestParams requestParams, HttpServletRequest request) { try { FileOutputStream fos = new FileOutputStream(savePath + requestParams.designer.fileName); if (requestParams.designer.password != null) { StiSerializeManager.serializeReport(report, fos, requestParams.designer.password); } else { StiSerializeManager.serializeReport(report, fos, true); } fos.close(); } catch (Exception e) { e.printStackTrace(); } } }; pageContext.setAttribute("handler", handler); pageContext.setAttribute("options", options); %> ...
最后,將網頁設計器標簽放到jsp頁面中:
... <stiwebdesigner:webdesigner handler="${handler}" options="${options}" /> </body> </html>
現在您可以將項目部署到 Tomcat 并運行它。
在下面的屏幕截圖中,可以看到示例代碼的結果:
Aspose、E-iceblue、FastReport、Stimulsoft等文檔/報表圖表類開發工具享超低折扣,如有需要可直接。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn