1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| password = request.getParameter("password");
if (sqlM.SafeCheck(username) == false || sqlM.SafeCheck(password) == false) { MSG = "alert('非法账号/密码输入');"; } else { String sql = "SELECT username from users where username = '" + username + "' and password = '" + password + "'"; ResultSet rs = sqlM.executeQuery(sql); if (rs != null && rs.next() == true && username.equals(rs.getString(1))) { usero.setUsername(username); usero.setPassword(password);
String username_code = java.net.URLEncoder.encode(username, "UTF-8"); String password_code = java.net.URLEncoder.encode(password, "UTF-8"); Cookie username_cookie = new Cookie("username", username_code); Cookie password_cookie = new Cookie("password", password_code); username_cookie.setMaxAge(60*60*24*3); password_cookie.setMaxAge(60*60*24*3); response.addCookie(username_cookie); response.addCookie(password_cookie);
response.setStatus(response.SC_MOVED_TEMPORARILY); response.setHeader("Location", "welcome.jsp");
return ; } else { MSG = "alert('账号或者密码出错');"; } }
|