也许这是一个简单的问题,但我对 JAVA 很陌生,我不明白为什么我的简单登录表单不起作用。这是我的项目结构的屏幕截图:在我的 index.jsp 中,我有以下形式:<form action="/LoginServlet" method="post" enctype="multipart/form-data" class="form-horizontal"> <div class="form-group"> <label>E-Mail Adresse</label> <input class="au-input au-input--full" type="email" name="un" placeholder="E-Mail"> </div> <div class="form-group"> <label>Passwort</label> <input class="au-input au-input--full" type="password" name="pw" placeholder="Passwort"> </div> <div class="login-checkbox"> <label> <input type="checkbox" name="remember">Merken </label> <label> <a href="#">Passwort vergessen?</a> </label> </div> <button class="au-btn au-btn--block au-btn--green m-b-20" type="submit">Anmelden</button></form>我的 LoginServlet.java,在 src 文件夹内看起来像这样:package controller;import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession;/** * Servlet implementation class LoginServlet */@WebServlet("/LoginServlet")public class LoginServlet extends HttpServlet { /** * */ private static final long serialVersionUID = 1L; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException { try { UserBean user = new UserBean(); user.setUserName(request.getParameter("un")); user.setPassword(request.getParameter("pw")); user = UserDAO.login(user); 如您所见,我有一个带有action="/LoginServlet". 在我正在使用的 LoginServlet.java 中,@WebServlet("/LoginServlet")但只要我提交表单,我就会收到一条 HTTP 状态 404 – 未找到消息。我真的不明白为什么?有谁知道我做错了什么?我错过了什么?任何帮助将非常感激。
2 回答

Cats萌萌
TA贡献1805条经验 获得超9个赞
<form action="LoginServlet" method="post" enctype="multipart/form-data" class="form-horizontal">
只需更新您的 action="LoginServlet" 删除 / 如果不起作用,请尝试从 Form 中删除 enctype="multipart/form-data"
确保 WebContent 文件夹中的 index.jsp 不在 Web-INF 中

至尊宝的传说
TA贡献1789条经验 获得超10个赞
<form action="/LoginServlet" method="post" enctype="multipart/form-data" class="form-horizontal">
您的表单使用 method="post",因此您需要覆盖 LoginServlet 上的 doPost 方法
添加回答
举报
0/150
提交
取消