亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

JSP - 向 servlet 提交表單

JSP - 向 servlet 提交表單

飲歌長嘯 2022-06-30 10:22:35
也許這是一個簡單的問題,但我對 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 中


查看完整回答
反對 回復 2022-06-30
?
至尊寶的傳說

TA貢獻1789條經驗 獲得超10個贊

<form action="/LoginServlet" method="post" enctype="multipart/form-data" class="form-horizontal">

您的表單使用 method="post",因此您需要覆蓋 LoginServlet 上的 doPost 方法


查看完整回答
反對 回復 2022-06-30
  • 2 回答
  • 0 關注
  • 111 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號