问题遇到的现象和发生背景
Tomcat版本:8.0.36
web版本:3.1
问题相关代码,请勿粘贴截图
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"
metadata-complete="false">
</web-app>
java代码:
package com.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
@Override
public void init() throws ServletException {
System.out.print("开始初始化……\n");
}
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.print("开始处理请求……\n");
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.print("开始处理get请求……\n");
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.print("开始处理post请求……\n");
}
@Override
public void destroy() {
System.out.print("销毁servlet……\n");
}
}
运行结果及报错内容
HTTP Status 404 - /Study20220209/LoginServlet
type Status report
message /Study20220209/LoginServlet
description The requested resource is not available.
Apache Tomcat/8.0.36
尝试解决方法:
查了不少博客,基本都是要web版本3.0以上以及 metadata-complete="false",这两项都已经满足,但是仍然404