密码错误,未提示错误信息
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录</title>
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/login.css">
</head>
<body>
<div class="login">
<div class="header">
<h1>
<a href="/login.do">登录</a>
</h1>
<button></button>
</div>
<form action="/login.do" method="post">
<div class="name">
<input type="text" id="name" name="username">
<p></p>
</div>
<div class="pwd">
<input type="password" id="pwd" name="password">
<p></p>
</div>
<div class="btn-red">
<input type="submit" value="登录" id="login-btn">
</div>
<div class="error">
<c:if test="${USER.username}==null">
<span class="error"> ${MSG}</span>
</c:if>
</div>
</form>
</div>
</body>
</html>
// /toLogin.do /login.jsp
public void toLogin(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getRequestDispatcher("login.jsp").forward(request,response);
}
// /login.do
public void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username =request.getParameter("username");
String password = request.getParameter("password");
User user = userService.get(username,password);
if(user==null){
response.sendRedirect("toLogin.do");
request.setAttribute("MSG","密码或用户名错误,请重新登录");
}else{
HttpSession session = request.getSession();
session.setAttribute("USER",user);
response.sendRedirect("../category/list.do");
}
}
22
收起
正在回答 回答被采纳积分+1
3回答
4. SSM到Spring Boot入门与综合实战
- 参与学习 人
- 提交作业 323 份
- 解答问题 8263 个
本阶段将带你学习主流框架SSM,以及SpringBoot ,打通成为Java工程师的最后一公里!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星