Detailed explanation of the process of deploying Tomcat and creating the first web project in IDEA 2020.3.1

Detailed explanation of the process of deploying Tomcat and creating the first web project in IDEA 2020.3.1

Tomcat Introduction

Tomcat is a core project of the Jakarta project of the Apache Software Foundation, developed jointly by Apache, Sun and some other companies and individuals. Thanks to Sun's participation and support, the latest Servlet and JSP specifications can always be reflected in Tomcat. Tomcat 5 supports the latest Servlet 2.4 and JSP 2.0 specifications. Because Tomcat has advanced technology, stable performance, and is free, it is deeply loved by Java enthusiasts and recognized by some software developers, becoming a relatively popular Web application server.

Tomcat deployment

Download Tomcat
Open the tomcat homepage and select the version you want to download. I downloaded tomcat8.5 here.

insert image description here

According to the system type of your computer, select the 64-bit or 32-bit compressed package and decompress it.

insert image description here

After decompression

insert image description here

Open IDEA, click Run at the top, and select Edit Donfiguration... , click Templates , find Tomcat server, and click local

insert image description here
insert image description here
insert image description here

4. Click Configure... and select the unzipped file. Remember the name is apache-tomcat-8.5.61

insert image description here
insert image description here
insert image description here

insert image description here

Creating a web project

csd

First create an empty java project and take a screenshot here

insert image description here
insert image description here
insert image description here

Right click the project and click Add Framework Support , select the web application framework, and click OK

insert image description here
insert image description here

This will add a web directory to the project

insert image description here

Configure tomcat

insert image description here
insert image description here

insert image description here

If your error is not automatically handled here, it means that you did not do the previous step of configuring the web application.

( Habit ) Create two folders under WEB-INF: classes and lib
classes directory: Place bytecode files
lib directory: prevent jar packages that the project depends on

insert image description here

Configuring the project architecture

insert image description here
insert image description here
insert image description here
insert image description here

Click OK

( habit ) Change Application context / (here is to set the virtual directory. If it is /, you don’t need a virtual directory when accessing the website. You can directly enter localhost:8080 to access index.jsp)

insert image description here
insert image description here
insert image description here

Successful connection

insert image description here

The index.jsp file will be opened automatically.

insert image description here

Because index.jsp is the default homepage, there is no need to write a virtual directory. If you access other .html files, you need to write the file name after localhost:8080 (such as: localhost:8080/hello.html)

You can create a .java file under src and implement the servlet interface and its 5 methods, and write an output code under the service method, which will be used later.

insert image description here

Configuring the servlet

Method 1: Paste the following code in web.xml

 <!--Configure servlet-->
 <servlet>
 <servlet-name>demo1</servlet-name>
 <servlet-class>cn.utkvrjan.web.servlet.ServletDemo1</servlet-class>
 </servlet>

 <servlet-mapping>
 <servlet-name>demo1</servlet-name>
 <url-pattern>/demo</url-pattern>
 </servlet-mapping>

Paste it in the position shown in the picture

insert image description here

Method 2: Starting from Servlet 3.0, annotation configuration is supported. It is super simple. Just write @WebServlet(urlPatterns = "/demo1") or @WebServlet("/demo1") on the implementation class name to configure it.

insert image description here

Then start tomcat and enter localhost:8080/demo1 in the browser to access (Note: demo1 here is entered when configuring the servlet). The content you wrote under the service method of the servlet implementation class will be output in the IDEA console, which means that the servlet is configured correctly.

insert image description here
insert image description here

(Habit) Hot deployment : Change Tomcat to: When updating resources in the file, let Tomcat restart (re-deploy the project), so that you don't need to manually restart the server after changing the file, which is more convenient.

insert image description here
insert image description here

If you select Update resources and classes here, you will also need to redeploy when you change the Java code. Since there are many changes to the Java code, this may affect performance, so don't select it.

This is the end of this article about deploying Tomcat in IDEA 2020.3.1 and creating the first web project. For more information about deploying Tomcat in IDEA 2020.3 and creating the first web 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:
  • Detailed explanation of shell script for deploying multiple instances of a single tomcat in Linux
  • Implementation of multiple instances of tomcat on a single machine
  • Where is the project location deployed by IntelliJ IDEA using Tomcat?
  • Tomcat multi-instance deployment and configuration principles

<<:  Detailed explanation of MySQL backup and recovery practice of mysqlbackup

>>:  How to implement responsive layout with CSS

Recommend

Implementation of Webpack3+React16 code splitting

Project Background Recently, there is a project w...

Robots.txt detailed introduction

Robots.txt is a plain text file in which website ...

Nginx rush purchase current limiting configuration implementation analysis

Due to business needs, there are often rush purch...

How to fix the four sides of the table to scroll up, down, left and right

question: When I was doing project statistics rec...

Use a diagram to explain what Web2.0 is

Nowadays we often talk about Web2.0, so what is W...

Ideas and methods for incremental backup of MySQL database

To perform incremental backup of the MySQL databa...

Will this SQL writing method really cause the index to fail?

Preface There are often some articles on the Inte...

Simple implementation method of two-way data binding in js project

Table of contents Preface Publish-Subscriber Patt...

The difference between ENTRYPOINT and CMD in Dockerfile

In the Docker system learning tutorial, we learne...

JavaScript custom plug-in to implement tab switching function

This article shares the specific code of JavaScri...

Vue implements multiple selections in the bottom pop-up window

This article example shares the specific code of ...