How to configure Tomcat and run your first Java Web project on IntelliJ IDEA 2018

How to configure Tomcat and run your first Java Web project on IntelliJ IDEA 2018

1 Download and start Tomcat

Go to the official website http://tomcat.apache.org/ and download the latest version of Tomcat 9

insert image description here

Download according to your computer version, I am using Windows 64-bit

insert image description here

After downloading, just unzip it.
Find the directory you unzipped, open the /bin directory under the folder, where startup.bat starts tomcat and shutdown.bat shuts down tomcat

insert image description here

After double-clicking startup.bat to start tomcat, open http://localhost:8080. If you enter the following interface, it means that the startup is successful.

insert image description here

2 Configure environment variables for Tomcat 9 in win10

Right-click "My Computer", click "Properties", select "Advanced System Variables"

insert image description here

Select the Advanced tab -> Environment Variables

insert image description here

In "System Variables", add system variables and add the following:
Create a new variable name: CATALINA_BASE
Variable value: E:\SoftWares\tomcat9\apache-tomcat-9.0.8 //Copy the tomcat decompression directory on your own computer

Create a new variable name: CATALINA_HOME
Variable value: E:\SoftWares\tomcat9\apache-tomcat-9.0.8 //Copy the tomcat decompression directory on your own computer

Click OK.
Then edit and modify the variable values ​​​​of CLASSPATH and Path.
Add the following to the ClassPath variable value: %CATALINA_HOME%\lib\servlet-api.jar; (note that you need to add the English “;” after the original variable value)
Add the following to the Path variable value: %CATALINA_HOME%\bin;%CATALINA_HOME%\lib (note that you need to add the English “;” after the original variable value)
Just click OK.

insert image description here

Finally, verify whether the configuration is successful.
Use the keyboard win+R to enter cmd, enter the startup command, if the following picture appears, it means the configuration is successful.

insert image description here

3 Create the first JavaWeb project in IDEA

Click File -> New -> Project…

insert image description here

Select Java -> Web Application, then click Next.

insert image description here

Give a project name, here we take JavaWebTest as an example, and then click Finish.

insert image description here

The project directory structure is as follows:

insert image description here

Modify the code in index.jsp to facilitate testing later. The code is as follows:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
 <head>
 <title>$Title$</title>
 </head>
 <body>
 Hello world!
 </body>
</html>

4 Configure Tomcat and run the project on IntelliJ IDEA 2018

Open IDEA and click Run-Edit Configurations…

insert image description here

Click the "+" sign, then find Tomcat Server and select Local

insert image description here

Under the Tomcat Server -> Unnamed -> Server -> Application server project, click Configuration, find the local Tomcat server (that is, the decompression path above), and then click the OK button. You can change Unnamed to another name, such as Tomcat 9

insert image description here

Then go to the Deployment tab next to it, click the "+" sign, select Artifact, select the project name

insert image description here

As shown in the figure below, you can also modify the name of the Application context path to make it simpler, and then click OK.

insert image description here

After configuration, you can see the following picture on the project interface and click Run.

insert image description here

Operation Results

insert image description here

Summarize

This is the end of this article about configuring Tomcat on IntelliJ IDEA 2018 and running the first JavaWeb project. For more information about configuring Tomcat on IntelliJ IDEA 2018 and running the first JavaWeb project, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • JavaWeb Getting Started: Creating a Web Project, Configuring Tomcat with Idea
  • Java Web Development [Tomcat Environment Configuration] MyEclipse+IDEA Configuration Tutorial
  • Create a Maven Javaweb project in idea and configure it (graphic tutorial)
  • Solve the mysql8.0.15 configuration problem of javaweb in idea
  • IDEA 2021 configuration JavaWeb project super detailed tutorial

<<:  js realizes the non-select drop-down box version of the three-level linkage of provinces, cities and districts

>>:  Detailed steps for configuring mysql8.0.20 with binlog2sql and simple backup and recovery

Recommend

Tutorial on how to remotely connect to MySQL database under Linux system

Preface I recently encountered this requirement a...

A brief analysis of MySQL parallel replication

01 The concept of parallel replication In the mas...

How to modify the forgotten password when installing MySQL on Mac

1. Install MySQL database on mac 1. Download MySQ...

React Class component life cycle and execution order

1. Two ways to define react components 1. Functio...

MySQL slow query method and example

1. Introduction By enabling the slow query log, M...

Manually implement the two-way data binding principle of Vue2.0

In one sentence: Data hijacking (Object.definePro...

CSS and HTML and front-end technology layer diagram

Front-end technology layer (The picture is a bit e...

HTTP Status Codes

This status code provides information about the s...

Eight ways to implement communication in Vue

Table of contents 1. Component Communication 1. P...

How to embed flash video format (flv, swf) files in html files

Flash file formats: .FLV and .SWF There are two ex...