Creation and configuration of a Web project (full version)

Open your idea:

1. Create a new Maven project:

Choose one of the following two situations:
Insert picture description here
Insert picture description here
Then first select Maven in the pop-up window, click next:
Insert picture description here
select the location where your project is to be stored, and the project name: (click Finish)
Insert picture description here

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>

Insert picture description here
Then click Maven on the right, and then click Refresh to deploy the project
Insert picture description here

3. Tomcat deployment:

Insert picture description here
Insert picture description here
Insert picture description here

Insert picture description here
Modify the context path: (you know the name yourself) For
example: localhost:8080/your context path/specific servlet
Insert picture description here
Tomcat version You can choose which version you installed at the beginning:
Insert picture description here

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
Insert picture description here
Insert picture description here

<?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

Guess you like

Origin blog.csdn.net/qq_45658339/article/details/112249187