为了账号安全,请及时绑定邮箱和手机立即绑定

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 关注
  • 88 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号