创建一个Maven项目

1.创建maven项目

image


建立webapp包,并且建立WEB-INF包
image


建立WEB-INF
image


建立web.xml
image

把下面粘贴到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>

配置maven地址
image

配置自己的路径
image

配置war包
image

点击自动导入
image

2.配置服务器

配置tomcat
image


添加tmocat
image


选择自己的tomcat路径
image


增加依赖
image


image

3.导依赖

把下面内容复制到
image

<dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>javax.servlet.jsp-api</artifactId>
            <version>2.3.3</version>
        </dependency>
    </dependencies>

4.写相关代码

image
配置servlet请求
这两个名字要一样
image

在Servlet中书写代码
写代码
image

 response.setContentType("text/html;charset=utf-8");
 response.sendRedirect("/hello.html");
 System.out.println("========");

建一个html
image

HTML
image

5.运行

image

image

image

posted @ 2022-07-16 10:00  笑到肚子疼  阅读(41)  评论(0)    收藏  举报