此鞋必中
2021-12-08 16:56
采纳率: 60%
浏览 26

登陆界面的一个映射,为什么输入的有账号密码,还是输入了空密码或者空账号

@WebServlet(name = "loginServlet",urlPatterns = "/loginServlet")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServleResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String type = request.getParameter("type");
        System.out.println("type ="  + type);
        if("trueLogin".equals(type)){//执行登录
            String userName = request.getParameter("userName");
            String pwd = request.getParameter("pwd");
            if (userName == null || "".equals(userName.trim())
                    || pwd == null || "".equals(pwd.trim())){
                request.setAttribute("message","用户名或密码不能为空");
                request.getRequestDispatcher("/WEB-INF/login.jsp").forward(request,response);
                return ;
            }
            AdminService adminService = new AdminServiceImpl();
            AdminDO adminDO = adminService.ValidateLogin(userName);
            adminDO =adminService.ValidateLogin(userName);
            if ( adminDO !=null && pwd.equals(adminDO.getPwd())){
                //放到Session之前清空敏感信息密码
                adminDO.setPwd(null);
                request.getSession().setAttribute("admin",adminDO);
                System.out.println("跳转到主页面");
                response.sendRedirect(request.getContextPath()+"/studentServlet?type=toStudentManage");
            }else{
                request.setAttribute("message","用户名或密码不正确");
                request.getRequestDispatcher("/WEB-INF/login.jsp").forward(request,response);
            }
        }else{
            request.getRequestDispatcher("/WEB-INF/login.jsp").forward(request,response);
        }

    }
}


img

img

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题