Servlet重定向到错误的.JSP,导致404错误

时间:2019-03-19 18:46:39

标签: rest jsp jsf servlets http-status-code-404

因此,每当用户提供无效的用户名/密码时,我都试图让我的Servlet重定向到我的/login.jsp。但是,当我这样做时,它会重定向到错误的网址,并给出未找到的404错误。它应该重定向到:http://localhost:8030/KwetterApp/login.jsp,但是重定向到:http://localhost:8030/login

这是我的servlet:

@WebServlet(name = "LoginServlet", urlPatterns = { "/login" })
public class LoginServlet extends HttpServlet {
    UserService service = new UserService();

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        String username = request.getParameter("Username");
        String password = request.getParameter("Password");
        User user = service.checkLogin(username, password);

        if (user != null) {
            session.setAttribute("userList", service.getAllUsers());
            session.setAttribute("user", user);

            if (user.getRole().equals(Role.ADMIN)) {
                response.sendRedirect("manage.jsp");
            }
            else {
                //ToDo
            }
        }
        else {
            response.sendRedirect("login.jsp");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}

Here is how my directory looks

0 个答案:

没有答案