Tomcat installation and use

Tomcat

About Tomcat

# What is Tomcat?
Tomcat Is a lightweight based Java Free and open source Web The server/Servlet Container.

# What can Tomcat do?
Deploy your Web engineering, Provide access control services for your web resources.

# The origin of the name Tomcat?
Tomcat It is a wild cat that does not rely on humans and lives independently. 
Tomcat The original intention of taking this name is to hope that this server can be self reliant and self-sufficient, such as Tomcat Such a wild animal generally does not rely on other plug-ins, but can be provided independently web The effect of service.

# Tomcat official download
https://tomcat.apache.org/download-80.cgi

# Tomcat official help documentation
http://tomcat.apache.org/tomcat-8.0-doc/introduction.html

# Tomcat official API documentation
http://tomcat.apache.org/tomcat-8.0-doc/api/index.html

# Tomcat official FAQ
https://cwiki.apache.org/confluence/display/TOMCAT/FAQ

Installation configuration

No matter what platform you deploy Tomcat on, you need to install Java and configure environment variables first, because Tomcat is based on Java.

Install under Windows

Add link description

1. Download and unzip
2. Environmental variables

New environment variable
Variable name: CATALINA_HOME
Variable value: Tomcat installation directory
Variable name: CATALINA_BASE
Variable value: Tomcat installation directory

Add to Path
%CATALINA_HOME%\bin
%CATALINA_HOME%\lib

Note: CATALINA_BASE is not required

3. Start service

Start service
Open cmd
Input: startup bat

Shut down service
Open cmd
Input: shutdown bat

Note: or go directly to the Tomcat installation directory/ In the bin directory, double clicking directly to run the corresponding bat program can also achieve the same effect.

Installing under Linux

Centos 7 is used here. Other Linux steps are the same, but the commands are slightly different.

1. Download and unzip
# decompression
tar -zxvf apache-tomcat-8.5.69.tar.gz
2. Environmental variables
# tomcat env
export CATALINA_HOME=/usr/local/tomcat-8.5.69
export PATH=$CATALINA_HOME/bin:$PATH

source env.sh 
3. Start service

Start service
./ Under bin
Enter:/ startup.sh

Shut down service
./ Under bin
Enter:/ shutdown.sh

Installation related

Version compatible
Applet specificationJSP specificationEL specificationWebSocket specificationJasic specificationApache Tomcat versionLatest releaseSupported Java versions
6.0undeterminedundeterminedundeterminedundetermined10.1.x10.1.0-M4 (alpha)11 and beyond
5.03.04.02.02.010.0.x10.0.108 and beyond
4.02.33.01.11.19.0.x9.0.528 and beyond
3.12.33.01.11.18.5.x8.5.687 and beyond
3.12.33.01.1Not applicable8.0.x (replaced)8.0. 53 (superseded)7 and beyond
3.02.22.21.1Not applicable7.0.x (archived)7.0. 109 (archive)6 and later (WebSocket version 7 and later)
2.52.12.1Not applicableNot applicable6.0.x (archived)6.0. 53 (archive)5 and beyond
2.42.0Not applicableNot applicableNot applicable5.5.x (archived)5.5. 36 (archive)1.4 and later
2.31.2Not applicableNot applicableNot applicable4.1.x (archived)4.1. 40 (archive)1.3 and later
2.21.1Not applicableNot applicableNot applicable3.3.x (archived)3.3. 2 (archive)1.1 and later
directory structure
bin  	# Script startup directory
conf 	# Profile directory
lib  	# Dependent packages for tomcat operation
logs 	# Log file directory
temp 	# Temporary file directory
webapps # Used to store applications
    --docs  # file
    --examples # Example
    --host-manager # Virtual host web management interface
    --manager # Management interface
    --ROOT # Applications accessed by default
work # The temporary working directory of the deployed Web application, which can be deleted when we need to clear the cache Then restart tomcat

Deployment project

Mode 1
Directly in./webapp/Create project folder under directory, You can access it by placing a web page file inside.
visit: http://localhost:8080 / project directory / Web page file
Mode II
Package items into war package, Put./webapp/Directory, start-up tomcat The deployment is automatically decompressed when.
hit war Package command: jar -cvf xxx.war *
visit: http://localhost:8080 / project directory / Web page file
Mode III
stay conf/server.xml In file Host Just configure the path of the item in the label body.(Not recommended)
<Context docBase="Project path" path="Access path" />
visit: http://localhost:8080 / access path / Web page file
Mode 4
stay conf/Catalina/localhost Create a directory with any name xml file, Just configure it in the file.(recommend)
<Context docBase="Project path" />
visit: http://localhost:8080/xml file name / Web page file

Modification of default configuration

Modify default port
stay ./conf/server.xml Modify in file

    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

Put the above port="8080"Change to the desired port number, Note that it conflicts with other ports~
Modify default encoding
stay ./conf/server.xml Modify in file

    <Connector port="8080" protocol="HTTP/1.1"
			  useBodyEncodingForURI="true"
			  URIEncoding="UTF-8"
               connectionTimeout="20000"
               redirectPort="8443" />

Append after the first line above
    useBodyEncodingForURI="true"
    URIEncoding="UTF-8"
You can also modify it to other code sets~
Configuration file server XML explanation
https://www.cnblogs.com/kismetv/p/7228274.html
https://www.cnblogs.com/starhu/p/5599773.html

Keywords: Java Linux Windows Tomcat

Added by galayman on Thu, 23 Dec 2021 15:28:20 +0200