在Tomcat上找不到错误404 Servlet

时间:2018-06-28 10:10:42

标签: java jsp tomcat servlets web-applications

你好,我在Eclipse上编码,我使用Tomcat 9.0服务器

这是WebContent / Login-Logout /文件夹中的JSP:

  <%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <title>Login</title>

</head>
<body>
<form action="/Login" method="post">
<fieldset>
    <label for="username">login</label>
    <input id="username" type="text" name="username" placeholder="enter login">
    <br>
    <label for="password">Password</label>
    <input type="password" id="username" name="username" placeholder="enter password">
    <br>
    <input type="submit" value="Login">
    <input type="reset" value="Reset">
</fieldset>
</form>
</body>
</html>

这是WEB-INF / lib中的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">

</web-app>

这就是src / control文件夹中的Servlet:

package control;

import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;

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

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

        String username= request.getParameter("username");
        String password= request.getParameter("password");
        String redirectedPage;

        try {
            checkLogin(username,password);
            request.getSession().setAttribute("adminRoles", new Boolean(true));
            redirectedPage="/adminPage.jsp";
        }catch(Exception e) {
            request.getSession().setAttribute("adminRoles",new Boolean(false));
            redirectedPage="Login-Logout/login-form.jsp";
        }

        response.sendRedirect(request.getContextPath()+redirectedPage);
    }

    private void checkLogin(String username, String password)
        throws Exception{

        if("root".equals(username)&& "admin".equals(password)) {

        }else {
            throw new Exception("Invalid login and password");
        }

    }
}

为什么每次我提交表单时都会显示此错误? 我已经尝试在web.xml上使用<servlet><servlet-mapping>东西,但是没有用

错误消息说: 错误404 讯息:/登入 说明原始服务器找不到目标资源的当前表示,或者不愿意透露其存在。

0 个答案:

没有答案