Eclipse 404 请求的资源不可用

Eclipse 404 Requested resource not available

我已经为这个问题苦苦挣扎了几个小时,但我似乎无法弄清楚问题出在哪里。做了很多谷歌搜索和挖掘,但似乎没有任何效果。我正在使用 Eclipse 开发 Web 应用程序,在访问资源时出现以下错误:

HTTP Status 404 - /EditForm
type Status report

message /EditForm

description The requested resource is not available.

一些背景信息:我正在使用 JSP 提交表单,该表单旨在使用用 java 编写的 servlet 来处理信息。 它被称为 editProfile.jsp,这是提交带有信息的表单的部分。

  <form CLASS="form-horizontal" METHOD=POST ACTION="/EditForm">

    <div class="form-group">
            <label class="control-label col-sm-2"><b>New Address</b></label>
            <INPUT TYPE=TEXT PLACEHOLDER="Type new address here." NAME=address SIZE=20><BR>
    </div>
    <div class="submit_btn col-sm-2"><INPUT TYPE=SUBMIT></div> 

  <form>

Servlet如下:

 package user;

import java.io.IOException;
import java.sql.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import database.*;


@WebServlet("/EditForm")
public class EditForm extends HttpServlet{


/**
 * 
 */
private static final long serialVersionUID = 102831973239L;
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException,ServletException {

    HttpSession session = request.getSession();
    String currForm =(String) request.getParameter("currForm");
    String user = (String) session.getAttribute("username");



    if(currForm.equals("address")) {

        String sqlStmt = "UPDATE db.User SET address = '"+ currForm+"' WHERE username = '"+user+"';";
        doSQL(sqlStmt);
        response.sendRedirect("profile.jsp");

    }
    else if(currForm.equals("phone")) {

        String sqlStmt = "UPDATE db.User SET phone = '"+ currForm+"' WHERE username = '"+user+"';";
        doSQL(sqlStmt);
        response.sendRedirect("profile.jsp");

    }

    else if(currForm.equals("email")) {

        String sqlStmt = "UPDATE db.User SET email = '"+ currForm+"' WHERE username = '"+user+"';";
        doSQL(sqlStmt);
        response.sendRedirect("profile.jsp");

    }

}

public void doSQL(String stmt) {

    try {
        DatabaseOperation op = new DatabaseOperation();
        op.connect();
        op.executeQuery(stmt);

    } catch(Exception e) { e.printStackTrace(); }   

}

}

我的 WEB-INF 文件夹中的 Web.xml 是:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
 http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" 
 version="3.1">
 <display-name>Website</display-name>
 <welcome-file-list>
     <welcome-file>index.html</welcome-file>
     <welcome-file>index.htm</welcome-file>
     <welcome-file>index.jsp</welcome-file>
     <welcome-file>default.html</welcome-file>
     <welcome-file>default.htm</welcome-file>
     <welcome-file>default.jsp</welcome-file>
 </welcome-file-list>

<servlet>
  <servlet-name>EditForm</servlet-name>
  <servlet-class>user.EditForm</servlet-class>  
</servlet>

</web-app>

我的应用目录结构:

   --Website
        |--Deployment Descriptor: Website
        |--JAX-WS Web Services
        |--Java Resources
        |      |--src
        |      |   |--user(package)
        |      |         |--EditForm.java
        |      |
        |      |--Libraries   
        |
        |--JavaScript Resources
        |--Referenced Libraries
        |--build
        |--WebContent
        |      |--META-INF
               |--WEB-INF
               |    |--lib
               |    |--web.xml
               |
               |--editProfile.jsp

如果有人能给我指出正确的方向并告诉我我做错了什么,我的资源无法访问,我将不胜感激。谢谢。

我认为您没有正确设置 servlet 的路径。而不是 action=/EditForm 尝试去 action=../EditForm

一个 Servlet 容器可以承载多个 Web 应用程序,因此您正在映射的 URI“/EditForm”只会在部署在服务器上时匹配相对于您的 Web 应用程序上下文路径的请求,而不是“/EditForm”绝对。 pageContext.getServletContext().getContextPath() 可以为您提供该路径,如果您想使用 JSP 表达式将它添加到 form action 值(假设您不想对其进行硬编码)。

如果您使用 javax.servlet.annotation.WebServlet 注释,您也不需要在部署描述符中声明 Servlet,至少不需要,除非您要在部署中用它做其他事情描述符也是如此。