创建一个Maven项目
1.创建maven项目

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

建立WEB-INF

建立web.xml

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

配置自己的路径

配置war包

点击自动导入

2.配置服务器
配置tomcat

添加tmocat

选择自己的tomcat路径

增加依赖


3.导依赖
把下面内容复制到

<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.写相关代码

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

在Servlet中书写代码
写代码

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

HTML

5.运行



浙公网安备 33010602011771号