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
1. Download and unzip
-
Tomcat 10.0
-
Tomcat 9.0
-
Tomcat 8.5
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
-
Tomcat 10.0
-
Tomcat 9.0
-
Tomcat 8.5
# 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 specification | JSP specification | EL specification | WebSocket specification | Jasic specification | Apache Tomcat version | Latest release | Supported Java versions |
---|---|---|---|---|---|---|---|
6.0 | undetermined | undetermined | undetermined | undetermined | 10.1.x | 10.1.0-M4 (alpha) | 11 and beyond |
5.0 | 3.0 | 4.0 | 2.0 | 2.0 | 10.0.x | 10.0.10 | 8 and beyond |
4.0 | 2.3 | 3.0 | 1.1 | 1.1 | 9.0.x | 9.0.52 | 8 and beyond |
3.1 | 2.3 | 3.0 | 1.1 | 1.1 | 8.5.x | 8.5.68 | 7 and beyond |
3.1 | 2.3 | 3.0 | 1.1 | Not applicable | 8.0.x (replaced) | 8.0. 53 (superseded) | 7 and beyond |
3.0 | 2.2 | 2.2 | 1.1 | Not applicable | 7.0.x (archived) | 7.0. 109 (archive) | 6 and later (WebSocket version 7 and later) |
2.5 | 2.1 | 2.1 | Not applicable | Not applicable | 6.0.x (archived) | 6.0. 53 (archive) | 5 and beyond |
2.4 | 2.0 | Not applicable | Not applicable | Not applicable | 5.5.x (archived) | 5.5. 36 (archive) | 1.4 and later |
2.3 | 1.2 | Not applicable | Not applicable | Not applicable | 4.1.x (archived) | 4.1. 40 (archive) | 1.3 and later |
2.2 | 1.1 | Not applicable | Not applicable | Not applicable | 3.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