Open your idea:
1. Create a new Maven project:
Choose one of the following two situations:
Then first select Maven in the pop-up window, click next:
select the location where your project is to be stored, and the project name: (click Finish)
2. Configure pom.xml:
Added in the pop-up pom.xml:
<!-- 1、打包方式 -->
<packaging>war</packaging>
<!-- 2、项目的基本信息 -->
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<!-- 3、添加依赖 -->
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
Then click Maven on the right, and then click Refresh to deploy the project
3. Tomcat deployment:
Modify the context path: (you know the name yourself) For
example: localhost:8080/your context path/specific servlet
Tomcat version You can choose which version you installed at the beginning:
4. Code preparation:
Create a webapp package under the main package, then create a WEB-INF package under the webapp package, and finally add web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
</web-app>
We write the back-end code under the java package and the front-end code under the webapp package