404 - 我的jsp无法找到servlet

时间:2017-12-05 17:11:44

标签: maven jsp servlets netbeans http-status-code-404

我想从我的jsp调用我的servlet,我的服务器返回404错误消息。请问有人帮帮我吗?

JSP - regsiter.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet"
    href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
</head>
<body>
    <div class="container">
        <h2>Register</h2>
        <form method="post" action="RegisterUser">
            <p>
                <c:out value="${error}" />
            </p>

            <p>
                E-mail <input type="text" name="email" />
            </p>
            <p>
                Name <input type="text" name="name" />
            </p>
            <p>
                Password <input type="password" name="password1" />
            </p>
            <p>
                Password again <input type="password" name="password2" />
            </p>
            <p>
                <input type="submit" value="Regsiter" />
            </p>
        </form>
    </div>
</body>
</html>

我的Servlet:RegisterUser.java:

package services;

import database.User;
import database.UserProvider;
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(name = "RegisterUser", urlPatterns = {"/RegisterUser"})
public class RegisterUser extends HttpServlet {


    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        String email = request.getParameter("email");
        String name = request.getParameter("name");
        String password1 = request.getParameter("password1");
        String password2 = request.getParameter("password2");
        UserProvider userProvider = new UserProvider();


        if (password1.equals(password2)) {
            userProvider.addUser(new User(email, name, password1));
             request.getRequestDispatcher(request.getContextPath() + "/forum.jsp").forward(request, response);

        } else {
            request.setAttribute("error", "Passwords don't match!");
            request.getRequestDispatcher("register.jsp").forward(request, response);
        }
    }


}

我的web.xml版本是3.1,所以我没有使用serlet-mapping。 我的javax.servlet-api版本是3.1.0。这是一个maven项目,所以它是一个依赖项。

我非常感谢帮助,因为这个问题是我大学毕业论文的一部分。 :d

非常感谢:)。

0 个答案:

没有答案