This tutorial shows the basics of running the web viewer in the reporting tool for Java. For example, show the report with Dashboards on the web page.

First, we need to create the Dynamic Web Project.

Next add the Stimulsoft Java Libs to the project.

Also you can convert to Maven project and configure the pom.xml file to use libs from 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>webviewer</groupId>
	<artifactId>webviewer</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>

Next we need to create the 'web.xml' file in the 'WebContent/WEB-INF' folder. Here we configure the StimulsoftResource servlet that retrieves the content such as *.js and images files, and also the StiWebViewerActionServlet that operate with the java web viewer:
<?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 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
		id="WebApp_ID" version="2.5">
	<display-name>stimulsoft_webviewer</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>StimulsoftAction</servlet-name>
		<servlet-class>com.stimulsoft.webviewer.servlet.StiWebViewerActionServlet</servlet-class>
	</servlet>
	<servlet-mapping>
		<servlet-name>StimulsoftAction</servlet-name>
		<url-pattern>/stimulsoft_webviewer_action</url-pattern>
	</servlet-mapping>
</web-app>

In the next step we need to create the 'index.jsp' page in the 'WebContent' folder. Here we load the 'Dashboards.mrt' report template file and render the report. Also we can configure the web viewer, for example set the background color to Gray. Finally, put the web viewer tag to the jsp page:
<%@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"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Stimulsoft Reports for Java</title>
</head>
<body>
	<%
		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);
	%>
	<stiwebviewer:webviewer report="${report}" options="${options}" />
</body>
</html>

Now you can deploy the project to the Tomcat and run it.


In the screenshot below you can see the result of the sample code:

Running the Viewer

By using this website, you agree to the use of cookies for analytics and personalized content. Cookies store useful information on your computer to help us improve efficiency and usability. For more information, please read the privacy policy and cookie policy.