Article directory
1. Introduction to Tomcat
What is Tomcat
Tomcat is a core project of the Apache Software Foundation. It is an open source and free lightweight web server that supports a small amount of Servlet/jspJavaEE规范
. Tomcat is also called a Web container, Servlet container.
Official website: https://tomcat.apache.org/
What is JavaEE
JavaEE: Java Enterprise Edition, Java Enterprise Edition. Refers to the sum of technical specifications for Java enterprise-level development. Contains 13 technical specifications: JDBC, JNDI, EJB, RMI, JSP, Servlet, XML, JMS, Java IDL, JTS, JTA, JavaMail, JAF
2. Tomcat usage configuration
2.1. Tomcat download and start
Tomcat download and installation
- Download: https://tomcat.apache.org/
- Installation: Tomcat is a green version, just decompress it directly. Suggestion: Do not have a Chinese directory, and the directory level should not be too deep.
- Open
apache-tomcat
directory and you will see the following directory structure. You need to understand the content contained in each directory
Tomcat starts and shuts down
- Startup: Double-click: bin\startup.bat
- closure
- Directly x out the running window: force close
- bin\shutdown.bat: normal shutdown
- ctrl+c: Normal shutdown
Tomcat access
Access method: browser inputlocalhost:8080
, Tomcat default port is 8080
2.2. Tomcat startup garbled code
question
The console has Chinese garbled characters, and conf/logging.properties needs to be modified.
- Enter Tomcat's conf directory
- Find the logging.properties file
- Replace all UTF-8 inside with GBK
注意:
It is recommended to use Vscode to open or other tools to directly search and replace to avoid errors.
2.3. Tomcat port number modification
- Enter the conf directory of Tomcat
- Find the server.xml file and open it
- Find the following code location, probably on line 69, and modify port = the location you want.
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
- Port number conflict
3. Tomcat project deployment
Two methods of project deployment
- Copy the project directly to the webapps directory
- Use compressed file .war method
- Pack the entire project into a zip file using a compression tool
- Change the zip extension to war
- Copy it to the webapps directory and tomcat will automatically decompress it into a directory with the same name.
注意:
The files inside cannot have Chinese names
Deployment demonstration: copy the project directly to the webapps directory
- The project name is: hello, copy its files to the webapps directory
- After starting Tomcat, visit hello
Deployment demonstration: compressed file .war
- Compress project into zip file
- Change the zip extension to war
- Copy it to the webapps directory and tomcat will automatically decompress it into a directory with the same name.
- access test
4. Using Tomcat in IDEA
- The project can be packaged into a war package through Maven's package command, copy the war file to Tomcat's webapps directory, start Tomcat to deploy the project successfully, and then access it through a browser.
- However, during the development process, the content of the project will often change. It is very inconvenient to deploy tests in the above way.
- How to quickly use Tomcat in IDEA?
Integrate local Tomcat into IDEA
- Open the panel to add local Tomcat
- Specify local Tomcat
- Configure local Tomcat
Deploy the project into integrated Tomcat
Extended content: What is the difference between the two deployment project modes of xxx.war and xxx.war exploded?
-
The war mode is to convert the WEB project into a war package and publish the war package to the Tomcat server.
-
The war exploded mode publishes the WEB project to the Tomcat server in the location of the current folder.
-
After the war mode deployment is successful, there will be deployed project content in Tomcat's webapps directory.
-
After the war exploded mode is successfully deployed, there is no webapps directory in Tomcat, but the content in the target directory of the project is used for deployment.
-
It is recommended that everyone choose war mode for deployment, which is more in line with the actual situation of project deployment.