构建一个普通的maven项目 删除src目录 在项目里面建module
关于maven 父子工程的理解
父工程多一个module
子工程多一个parent
父项目的jar包 子工程可继承
maven 环境优化
根据tomcat 的 web.xml文件 修改项目中的web.xml为最新
将maven的结构优化
编写一个servlet 程序
package org.example.servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
/**
* @ClassName HTTPServlet
* @Description servlet
* @Date 2022/11/24
* @Author depressiom
*/
public class HTTPServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//req.getInputStream();
PrintWriter writer = resp.getWriter();
writer.println("hello,servlet");
}
}
编写一个servlet的映射
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
version="5.0"
metadata-complete="true">
<!-- servlet映射 -->
<!-- 注册servlet -->
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>org.example.servlet.HTTPServlet</servlet-class>
</servlet>
<!-- servlet的请求路径 -->
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>
配置Tomcat