Today is the eighty-seventh day for Liu Xiaoai to learn Java by herself.

Thank you for watching. Thank you.

Without further ado, let’s begin today’s lesson:


It is said that the new version of the development tool IDEA comes with Tomcat, regardless.

Today, learn about Tomcat from download, installation, and configuration to run.

After all, if many of these problems are not known, they will not be solved, and I will feel embarrassed to say that I have development experience in the future.

1. Introduction of Tomcat

First, understand the basic concepts of servers.

  • Server hardware: it can be thought of as a computer, but the processing power of the server is generally more powerful than the common computer.
  • Server software: An application that requires software installed on the server hardware to provide services.

And Tomcat is a Web application server software, of course, there are many other server software, but no matter, currently only learn Tomcat.

The reason is simple, because it’s open source and free.

1 download Tomcat

Search Tomcat online and find its official website to download:


1) Tomcat8

Now that the latest version has arrived at Tomcat10, it’s up to you to decide which version to follow, and I chose Tomcat8.

② Download the installation package

  • For Linux, download zip, which is the first one.
  • For MAC, download tar.gz, the second one.
  • For 32-bit Windows, download the 32-bit version.
  • For 64-bit Windows, download 64-bit.

After downloading, you will get a compressed package, that is, ③

(4) the Tomcat folder

I don’t have a thorough understanding of these folders, so I can roughly explain my own understanding:

  • Bin folder: The place to run the program.
  • Conf folder: short for Configuration, in which you can configure various parameters.
  • Lib folder: library shorthand, library, I look at the inside are all under the Java jar package. Was Tomcat developed using the Java language?
  • Logs folder: Where logs are stored.
  • Temp folder: Stores the cache.
  • Webapps folder: App stands for application, which is a place to store Web applications.

2Tomcat startup and shutdown

Tomcat is installation-free and can be started directly without a step-by-step installation.


1) bin folder

  • Batch file startup.bat. Click to run Tomcat.

  • Batch file shutdown.bat, click to close Tomcat.

How do I check whether Tomcat is running successfully?

2. Enter localhost: 8080 in the browser

Localhost is the local IP address, and Tomcat’s default port is 8080. In other words, enter this path to access Tomcat running locally.

  • If it runs successfully, an official page will appear.
  • If the run fails, there is no response.

Two, Tomcat installation problems

1 Click startup.bat and click Ok

Bat file with an editor and pause at the end of the text.

Click again to find out what is wrong:


① Configuration of environment variables

When I run the JRE_HOME environment variable, THERE is a problem.

So configure an environment variable for JRE_HOME on your computer.

② Configure environment variables

Note The path is jre in the JDK folder. The installation path varies according to your own requirements.

2 Port number conflict


① Enter the command

Windows+R, enter CMD to enter DOS, and then enter netstat -nao.

② Find port 8080

It has a corresponding PID value, so write that down.

3 Open the task manager

In the details, find the corresponding running program according to the PID and end it.

3. The problem about running garbled code


Garbled characters appear when Tomcat is running

Of course, this problem does not affect the program itself, can still run, do not solve the line, but its look and feel is not good.

As an OCD, definitely have to solve this problem.

(2) the conf folder

There is a logging.properties file in this folder, which is opened using notpad++(your own notepad will do).

(3) find logging. ConsoleHandle. Encoding

Change the coded character set from UTF-8 to GBK.

Note that only the corresponding encoding character set is required.

Iii. IDEA runs web projects

Ok, now that Tomcat is running, you can create a JavaWeb project with IDEA.


(1) the Java Enterprise

It’s an Enterprise.

One of the biggest differences between Java Enterprise and Java is that Java can run programs directly, whereas Java Enterprise requires a container, in this case Tomcat.

Tomcat will not run if it is not configured properly.

② Configure JDK and Tomcat

Things to watch:

Make sure you have the Tomcat and JDK paths configured for your environment variables, which you are using.

For example, I have several JDK files in my computer, because I have been confused about whether to use JDK8 or JDK14, so I didn’t delete them, so I might get mixed up.


Then check the project template and create your own project name.

A JavaWeb project is created.


① Project structure directory

  • SRC: Where the Java source code is stored.
  • Web: Stores static resources (HTML, CSS, JS) and JSPS.
  • Web-inf: This directory is not directly accessible by the browser. Some configuration information is written in this directory.

② Project operation

After the configuration, start the Tomcat startup.bat batch file.

Click Run, the page corresponding to index.jsp will appear in the browser, that is, the operation is successful.

Attachment: Tomcat starts automatically

In MySQL, there is a self-start configuration. When configured, MySQL automatically runs every time your computer is turned on.

So I thought, can Tomcat do that?

Startup. Bat file is a file that needs to be started every time you restart your computer.

Bat install in the Tomcat installation directory: service.bat install

If the installation fails, check the Java configuration of Tomcat8w.exe:


There is a tomcat8w. exe file in the Tomcat installation directory. Configure the path of the JVM. DLL file.

Then go to the Tomcat service in services (right-click computer – Administration), right-click the property and set it to automatic startup (delayed startup).

Note: automatic (delayed start).

If the service shuts down immediately after starting, the solution is as follows:


Right-click the properties and select the Login TAB to change the login identity to a local system account, allowing the service to interact with the desktop.

The reason for doing this is unclear, but it does solve the problem by shutting down the service itself.

I encountered this problem when installing MySQL, so I was impressed.

The last

Thanks for watching.

If you can, please give it a thumbs up. Thank you.