用servlet验证用户名密码
①String username = request.getParameter("username");
String password = request.getParameter("password");
if(username.equals("admin")&&password.equals("admin")){
response.sendRedirect(request.getContextPath()+"/login_seccess.jsp");
}else{
response.sendRedirect(request.getContextPath()+"/login_failed.jsp");
}
②Users u = new Users();
String username = request.getParameter("username");
String password = request.getParameter("password");
u.setUsername(username);
u.setPassword(password);
if(u.getUsername().equals("admin")&&u.getPassword().equals("admin")){
response.sendRedirect(request.getContextPath()+"/login_seccess.jsp");
}else{
response.sendRedirect(request.getContextPath()+"/login_failed.jsp");
}
}
第一种方法也可以判断用户名密码,教学里是第二种方法,为什么要实例化Users,用set和get方式来判断用户名密码呢?
直接request.getParameter()不就得了,老师的方法意义何在呢