自动登录:<input type="checkbox" name="auto" value="auto" ><br> <input type="submit" value="登录">
sevlet
String auto = req.getParameter("auto");
if(new LoginServiceImpl().login(username, password)) {
req.getSession().setAttribute("username", username);
if(auto==null) {
Cookie cookie = new Cookie("auto", null);
cookie.setMaxAge(60*60*24*3);
cookie.setPath(req.getContextPath()+"/");
resp.addCookie(cookie);
}else {
Cookie cookie = new Cookie("auto", username+"_"+password);
cookie.setMaxAge(60*60*24);
cookie.setPath(req.getContextPath()+"/");
resp.addCookie(cookie);
}
resp.sendRedirect("index.jsp");
}else {
resp.sendRedirect("login.jsp");
}
}