翻譯|使用教程|編輯:王香|2018-11-19 10:38:29.000|閱讀 1100 次
概述:本教程介紹了在Java報(bào)表工具中運(yùn)行Web設(shè)計(jì)器的基礎(chǔ)知識(shí)。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷售中 >>
相關(guān)鏈接:
本教程介紹了在Java報(bào)表工具中運(yùn)行Web設(shè)計(jì)器的基礎(chǔ)知識(shí)。例如,打開(kāi)Master-Detail- 詳細(xì)信息報(bào)表模板。
首先,我們需要?jiǎng)?chuàng)建動(dòng)態(tài)Web項(xiàng)目。
然后將Stimulsoft Java Libs添加到項(xiàng)目中。
您還可以轉(zhuǎn)換為Maven項(xiàng)目并配置pom.xml文件以使用Maven中的庫(kù)。
<project xmlns = “//maven.apache.org/POM/4.0.0” xmlns:xsi = “//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>
接下來(lái),我們需要在WebContent / WEB-INF文件夾中創(chuàng)建web.xml文件。在這里,我們配置StimulsoftResource servlet,它檢索諸如* .js和圖像文件之類的內(nèi)容,以及使用java web設(shè)計(jì)器操作的StiWebDesignerActionServlet。
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="//www.w3.org/2001/XMLSchema-instance" xmlns="//java.sun.com/xml/ns/javaee" xmlns:web="//java.sun.com/xml/ns/javaee/webapp_2_5.xsd" xsi:schemaLocation="//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文件夾中創(chuàng)建index.jsp頁(yè)面。在這里,我們加載Master-Detail.mrt報(bào)表模板文件并定義報(bào)表的數(shù)據(jù)路徑。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "//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<br< a=""> /> 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="//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/"); ...
我們還可以指定Web設(shè)計(jì)器選項(xiàng),例如設(shè)置必要的本地化。
.... StiWebDesignerOptions options = new StiWebDesignerOptions(); //options.setLocalization(request.getSession().getServletContext().getRealPath("/localization/de.xml")); ...
接下來(lái),我們需要實(shí)現(xiàn)StiWebDesigerHandler來(lái)填充報(bào)表數(shù)據(jù)并保存/加載報(bào)表模板。
.... 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); %> ...
最后,將web designer標(biāo)記放到j(luò)sp頁(yè)面。
... <stiwebdesigner:webdesigner handler="${handler}" options="${options}" /> </body> </html>
現(xiàn)在,您可以將項(xiàng)目部署到Tomcat并運(yùn)行它。
在下面的屏幕截圖中,您可以看到示例代碼的結(jié)果。
購(gòu)買(mǎi)Stimulsoft正版授權(quán),請(qǐng)點(diǎn)擊“”喲!
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn