Servlet 问题 - 资源不可用

Servlet issue - Resource not available

所以,我一直有这个问题,我从来不明白 servlet 是如何工作的,我的所有 java ee projects..

经常遇到同样的错误

我认为这是我 web.xml 的问题,但我不确定。

网络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>Register-Signup</servlet-name>
        <servlet-class>club.xxx.linxer.SignUp</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Register-Signup</servlet-name>
        <url-pattern>/Register</url-pattern>
    </servlet-mapping>

</web-app>

Servlet 代码 -

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();

        out.println("WORKS!");

    }

我的表单代码

<form class="modal-content" action="Register" method="post">

错误消息 -

HTTP Status 404 - /Linxer_war_exploded/ud/signup/Register
type Status report

message /Linxer_war_exploded/ud/signup/Register

description The requested resource is not available.

Apache Tomcat/9.0.0.M9

PROJECT STRUCTURE

我猜你的动作标签应该像 action="Linxer_war_exploded/Register".

如果你使用jsp那么你可以写

action="<%=request.getContextPath()%>/Register" 

使其动态化。