遇到问题:html跳转Servlet显示404
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>title</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<section>
<div>
<form action="Main_LoginServlet" method="post">
<p>
<button type="submit">登录</button>
</p>
</form>
</div>
</section>
</body>
</html>
package main_Login;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet(name = "Main_LoginServlet", urlPatterns = "/Main_LoginServlet")
public class Main_LoginServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out=response.getWriter();
out.println("a");
// RequestDispatcher requestDispatcher=request.getRequestDispatcher("/main_Login.html");
// requestDispatcher.forward(request,response);
}
}
运行结果及报错内容
html可以打开,但是Servlet打不开
我的解答思路和尝试过的方法
①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_4_0.xsd"
version="4.0">
<servlet>
<servlet-name>Main_LoginServlet</servlet-name>
<servlet-class>main_Login.Main_LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Main_LoginServlet</servlet-name>
<url-pattern>/Main_LoginServlet</url-pattern>
</servlet-mapping>
</web-app>
②tomcat也懵懵懂懂试过
③相对路径改绝对路径也试过
我想要达到的结果
能够正常让Servlet运行