【问题标题】:Servlet issue - Resource not availableServlet 问题 - 资源不可用
【发布时间】:2019-12-26 05:41:26
【问题描述】:

所以,我一直有这个问题,我从来不明白 servlet 是如何工作的,我的所有 java ee 项目都经常遇到同样的错误..

我认为这是我的 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_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

【问题讨论】:

  • 你的war部署在tomcat/webapps下面吗? club.xxx.linxer.SignUp 这里有文件吗 catalina.out 有什么错误吗?您的 servlet 是否扩展 HttpServlet 。也不知道为什么你的方法受到保护
  • 我正在使用 localhost 进行测试,是的,那里有一个 Servlet 类。

标签: java jsp tomcat servlets jakarta-ee


【解决方案1】:

我猜你的操作标签应该是action="Linxer_war_exploded/Register"

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

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

使其动态化。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-25
    • 2015-02-20
    • 2016-03-14
    • 1970-01-01
    • 2013-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多