Laughing girl2021
2021-07-19 23:17
采纳率: 100%
浏览 31
已采纳

javaweb练习登录错误显示错误页面,运行后一直是账户错误,不能切换密码错误,请大能看哈哪错了?


<!--案例&#45;&#45;&#45;&#45;登录错误时显示错误界面-->

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<center>
     <h2>用户登录</h2>
     <form action="login" method="get">
       <p>账号:<input type="text" name="name"></p>
       <p>密码:<input type="text" name="passWord"></p>
       <input type="submit" value="登录">
     </form>
</center>

</body>
</html>

package com.pojo.test1;

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

@WebServlet(name = "loginServlet", urlPatterns = "/login")
public class loginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String userName="daiping";
        String userPwd="123456";

        String name=request.getParameter("name");
        String passWord=request.getParameter("passWord");

        if (!name.equals("userName")){
            request.setAttribute("errorMessage","账户错误");
            request.getRequestDispatcher("/loginError.jsp").forward(request,response);
        }else if (!passWord.equals("userPwd")){
            request.setAttribute("errorMessage","密码错误");
            request.getRequestDispatcher("/loginError.jsp").forward(request,response);
        }

    }

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

    }
}

<%--
  Created by IntelliJ IDEA.
  User: pan
  Date: 2021/7/19
  Time: 17:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<center>
<h2>用户登录界面错误</h2>
    <div>
        <%=request.getAttribute("errorMessage")%>
    </div>

</center>
</body>
</html>

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

4条回答 默认 最新

  • Laughing girl2021 2021-07-20 19:36
    已采纳

    img

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • 查看更多回答(3条)

相关推荐 更多相似问题