I. Overview
1) Usage scenario: after deploying the report project on Tomcat and starting the server, users have to access a URL (http://localhost:8080/webroot/decision) before they can visit the decision-making system. Sometimes users wish to access the decision-making system via the server IP address, omitting the port number and webroot after the URL.
2) Solution: modify the port number and establish a virtual directory to enable users to directly enter the decision-making system by accessing an IP address (e.g., http://localhost).
II. Steps
1. Modify the port number
The default port of http is port 80. If no other web applications occupy port 80, we can set the port of Tomcat to 80. For detailed port setting, please refer to Operation and Maintenance of Tomcat Server.
< Connector port = "80" protocol = "HTTP/1.1" connectionTimeout = "20000" redirectPort = "8443" /> |
Restart the Tomcat server and enter http://localhost/webroot/decision in the browser to visit the decision-making platform.
2. Set the welcome screen
Each Web server has a default welcome screen, which can be modified to directly display the decision-making platform.
Create a new file a.jsp under the directory %Tomcat_home%\webapps\webroot, which serves as the default homepage of the Web server.
a.jsp calls the decision-making platform page through iframe. Input the following code:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
<head>
<title>FineReport</title>
<link rel="stylesheet" type="text/css" href="/decision/file?path=/com/fr/web/core/css/leaflet.css&type=plain&parser=plain"/>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<iframe id="reportFrame" src="decision" allowfullscreen="true"
name="itemslist" frameborder="0" width="100%" height="100%"></iframe>
</body>
</html>
Note
<link rel="stylesheet" type="text/css" href="/decision/file?path=/com/fr/web/core/css/leaflet.css&type=plain&parser=plain"/> This line of code is used to ensure that the map is normally displayed.
Of <iframe id="reportFrame" src="decision" allowfullscreen="true" name="itemslist" frameborder="0" width="100%" height="100%">, allowfullscreen="true" can ensure that the decision-making platform can be normally displayed when the page is maximized.
Restart the Tomcat server and enter http://localhost/webroot/a.jsp in the browser to display the login page of the decision-making system.
3. Establish a virtual directory
You can establish a virtual directory by modifying Tomcat configuration files.
1) Adjust the project path
The report project webroot is by default located under the directory %Tomcat_home%\webapps, and will be loaded when the server is started. After a virtual directory is established, the project webroot will be loaded again through configuration files when the Tomcat server is started. The project webroot is loaded twice, which triggers an error or server crash.
Therefore, users should relocate the project webroot from the directory %Tomcat_home%\webapps to somewhere other than a directory deployed on Tomcat, but on the same disk that the Tomcat project is stored.
In this article, the folder webroot which was located under %Tomcat_home%\webapps is relocated under D:\webroot, as shown below:
2) Modify the file server.xml
Modify the file %Tomcat_home%\conf\server.xml by adding the following code in the tag host in the file server.xml:
Input the following code:
<Context path="" docBase="D:\webroot" debug="0" reloadable="true" />
Modify the file as follows:
Description of each attribute in the tag Content:
Attribute | Meaning |
---|---|
Attribute | Meaning |
path | Virtual directory If you wish to display the homepage when entering an IP address, then leave the key value blank |
docBase | The path of the project The path of webroot set in 2.3.1 in this article, which is D:\webroot |
debug | Level of debug 0 means the minimal information available while 9 means the maximal information available |
reloadable | If true, then Tomcat will automatically test changes in directories /WEB-INF/lib and /WEB-INF/classes of an application and the file loading the application, which enables automatically loading the application without restarting Tomcat |
3) Modify the file web.xml in the FineReport 9.0 project
There is a file named web.xml in the 9.0 project and users can directly modify the script.
Modify the file %Tomcat_home%\conf\web.xml by adding a piece of code before the tag </web-app> at the bottom of the file web.xml to display a custom welcome screen a.jsp. Input the following script:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>a.jsp</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
4) Modify the file web.xml in the FineReport 10.0 project
There is no such file in the 10.0 project, so users have to create a file named web.xml
Create the file web.xml under the directory webroot\WEB-INF and input the following script:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="<a href="http://java.sun.com/xml/ns/j2ee" "="">http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance" "="">http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
<a href="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" "="">http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Template WebApp</display-name>
<mime-mapping>
<extension>msi</extension>
<mime-type>application/x-msi</mime-type>
</mime-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>a.jsp</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
See the figure below:
4. Preview the effect
Restart the Tomcat server and access http://localhost to visit a.jsp, which displays the decision-making platform page, as shown below:
III. Matters to be noticed
1. Incomplete display in IE9
1) Requirement
After deployment as described above, the page is incompletely displayed in IE9.
2) Solution
Modify the code in the file a.jsp in 2.2 in this article as follows:
<html>
<head>
<title>FineReport</title>
<meta http-equiv="X-UA-Compatible" content="chrome=1,IE=edge"/>
<link rel="stylesheet" type="text/css" href="/decision/file?path=/com/fr/web/core/css/leaflet.css&type=plain&parser=plain"/>
<style type="text/css">
html, body
{
margin: 0px 0px;
width: 100%;
height: 100%;
}
iframe
{
margin: 0px 0px;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<iframe id="reportFrame" src="decision" name="itemslist" frameborder="0"></iframe>
</body>
</html>
IV. Input the server address
1. Access the report project through the designer in the remote design mode
When inputting the server address, omit webroot but retain decision.
Item | Value |
---|---|
Item | Value |
Host name/IP | Fill in faithfully |
Port number | 80 |
Web application | Null |
Servlet | decision |
Username\password | Fill in faithfully |
For instance:
2. Access the decision-making platform on an App
When inputting the server address on a mobile terminal, omit webroot but retain decision.
For example, http://192.168.1.1:80/decision.