也許這是一個簡單的問題,但我對 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
提交
取消