java web designer 教程_【Stimulsoft Reports Java教程】运行Java Web Designer

本教程详细介绍了如何在Java环境中使用Stimulsoft Reports Java运行Web设计器,包括创建动态Web项目,添加Stimulsoft库,配置web.xml,创建index.jsp页面,加载报表模板,设置Web设计器选项,实现数据填充和保存/加载功能。通过此教程,读者将学会如何部署和运行Java Web Designer。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本教程介绍了在Java报表工具中运行Web设计器的基础知识。例如,打开Master-Detail- 详细信息报表模板。

首先,我们需要创建动态Web项目。

6f9bb743cb3e54011d4bcd15ca208383.png

然后将Stimulsoft Java Libs添加到项目中。

cddef660c1917caf9d579d8891258901.png

您还可以转换为Maven项目并配置pom.xml文件以使用Maven中的库。

xmlns:xsi = “http://www.w3.org/2001/XMLSchema-instance”

xsi:schemaLocation = “http:/ /maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd“ >

4.0.0 < / modelVersion>

webdesigner < / groupId >

webdesigner < / artifactId>

0.0.1-SNAPSHOT < / version>

war packaging>

src < / sourceDirectory>

maven-compiler-plugin < / artifactId>

3.5.1 < / version>

1.6 < / source>

1.6 < / target>

< / configuration>

< / plugin>

< / plugins>

< / build>

com.stimulsoft groupId>

stimulsoft-reports-libs < / artifactId>

2017.1.1 < / version>

< / dependency>

< / dependencies>

< / project>

接下来,我们需要在WebContent / WEB-INF文件夹中创建web.xml文件。在这里,我们配置StimulsoftResource servlet,它检索诸如* .js和图像文件之类的内容,以及使用java web设计器操作的StiWebDesignerActionServlet。

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 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

id="WebApp_ID" version="2.5">

stimulsoft_webdesigner

index.jsp

StimulsoftResource

com.stimulsoft.web.servlet.StiWebResourceServlet

StimulsoftResource

/stimulsoft_web_resource/*

StimulsoftDesignerAction

com.stimulsoft.webdesigner.servlet.StiWebDesignerActionServlet

StimulsoftDesignerAction

/stimulsoft_webdesigner_action

在下一步中,我们需要在WebContent文件夹中创建index.jsp页面。在这里,我们加载Master-Detail.mrt报表模板文件并定义报表的数据路径。

/> import="com.stimulsoft.report.dictionary.databases.StiXmlDatabase"%>

Stimulsoft Webdesigner for Java

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设计器选项,例如设置必要的本地化。

....

StiWebDesignerOptions options = new StiWebDesignerOptions();

//options.setLocalization(request.getSession().getServletContext().getRealPath("/localization/de.xml"));

...

接下来,我们需要实现StiWebDesigerHandler来填充报表数据并保存/加载报表模板。

....

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标记放到jsp页面。

...

现在,您可以将项目部署到Tomcat并运行它。

e4de5e267d542ffa8fb510485ee68b4e.png

在下面的屏幕截图中,您可以看到示例代码的结果。

b53167b0ae55ad27a65c56e4ec0b6e8d.png

购买Stimulsoft正版授权,请点击“咨询在线客服”哟!

标签:HTML5web报表JavaStimulsoft

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,尊重他人劳动成果

a6e1590ae4b228073faff3806334194e.png0

好文不易,鼓励一下吧!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值