【JavaWeb】Tomcat download and use

1 Introduction

Tomcat is a core project of the Apache Software Foundation. It is also an open source and free lightweight web server. It supports servlet/JSP and a small amount of JavaEE specifications. It is also a server commonly used in our learning JavaWeb. Tomcat is also known as the Web container,
Servlet Container. Servlet needs to rely on Tomcat to run

2.Tomcat download

Download address: https://tomcat.apache.org/
Note: Tomcat version and servlet version are related

After clicking, such an interface will appear, and the version of Tomcat can be selected on the left.
insert image description here
I download Tomcat8 here as a demo. There are many download methods here, just click zip.
insert image description here
After downloading, just unzip it.

The following are the directories obtained after decompression:
insert image description here
the following briefly introduces these directories:

  • bin: There are some executable programs/scripts in it, which is where Tomcat is started
  • conf: Express server configuration in .xml format
  • lib: Indicates some libraries that Tomcat depends on
  • longs: This is the log, the running log of Tomcat is here. If there is a problem with the program, you can use the log to troubleshoot the problem
  • temp: This directory stores temporary files generated by tomcat during operation
  • webapps: webapp is a website, a Tomcat can deploy multiple websites, so it is called "webapps"
  • work: tomcat has a work directory, which stores the cache of the page, the accessed jsp will be compiled, and the compiled files will be stored in the work directory

3. Start Tomcat

Note in advance: Tomcat is implemented based on Java, which requires jdk in the computer.

insert image description here
Find the shrinkup inside, there are two
insert image description here

I am Windows, so just click shutdown.bat to run it. If
insert image description here
you see the server startup in time here, the operation is successful.

If you click shutdown here, Tomcat can’t run, and the window disappears in a flash.
Then you can drag the corresponding shutdown file to the command prompt, run it and view the error message

Common problems that do not work:

  1. Check whether the JAVA_HOME environment variable is configured correctly
  2. If the port number conflicts, find the corresponding program and close it

At this point we enter in the browser 127.0.0.1:8080(8080 is the default port number of Tomcat)
insert image description here
Note: To successfully access this page, you must ensure that Tomcat is running

4. Modify the default port number of Tomcat

First find confthis directory, and double-click to enter the file
insert image description here
with a inside to open it directly, find the following code: modify it to the desired port number and save it.server.xml
insert image description here

insert image description here

5. Close Tomcat

There are three ways to close Tomcat: 1. Directly close the running window of Tomcat 2. Press ctrl c in the running window of Tomcat 3. Find the shatdown file in the bin directory and proceed. I will not demonstrate it to you
here

6. Deploy the project

Tomcat is a server, so you can deploy the project to Tomcat. The deployment method is also very simple, just put the project we wrote in the webapps directory of Tomcat. Here is a single static
html The file is deployed to tomcat. There are two methods

First of all, we need to create a good html file
insert image description here
. Enter the tomcat directory here, and find the ROOT directory in webapps
insert image description here
. Put the written html file in the ROOT directory.
insert image description here

In the bin directory, find startup.bat to run, start the Tomcat server
insert image description here
insert image description here
and then you can enter 127.0.0.1:8080/文件名to access the file
insert image description here

But this method is not very good. In actual development, our project cannot be just an html file. It should also be used with css and js files. If these files are copied to the ROOT directory, it will appear very Chaos. So we can create a separate directory, side by side with ROOT, to store the content we want to deploy.

Demonstration:
I created a test directory in wabapps.
insert image description here
Put the index.html I just wrote in the test directory.
insert image description here
Enter 127.0.0.1:8080/目录名/文件名to access the file
insert image description here
. Be sure to ensure that Tomcat is in the startup state when accessing, otherwise the access will fail!

Thank you for watching! I hope this article can help you!
"JavaWeb Column" is constantly being updated, welcome to subscribe!
"Wish to encourage you and work together!"
insert image description here

Guess you like

Origin blog.csdn.net/m0_63463510/article/details/129710111