本教程介绍了在Java报表工具中运行Web设计器的基础知识。例如,打开Master-Detail- 详细信息报表模板。
首先,我们需要创建动态Web项目。
然后将Stimulsoft Java Libs添加到项目中。
您还可以转换为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 Javafinal 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并运行它。
在下面的屏幕截图中,您可以看到示例代码的结果。
购买Stimulsoft正版授权,请点击“咨询在线客服”哟!
标签:HTML5web报表JavaStimulsoft
本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,尊重他人劳动成果
0
好文不易,鼓励一下吧!