老师的dologin.jsp的else这块代码有问题
当我不选记住密码时,账号和密码无法传递到users.jsp,也就无法展示信息。
当我不选记住密码时,账号和密码无法传递到users.jsp,也就无法展示信息。
2019-08-05
我修改了下
<%
request.setCharacterEncoding("utf-8");
//首先判断用户是否选择了记住登录状态
String isUseCookies = request.getParameter("isUseCookie");
String username = request.getParameter("username");
String password = request.getParameter("password");
if("isUseCookie".equals(isUseCookies))
{
//把用户名和密码保存在Cookie对象里面
//使用URLEncoder解决无法在Cookie当中保存中文字符串问题
Cookie usernameCookie = new Cookie("username",URLEncoder.encode(username,"utf-8"));
Cookie passwordCookie = new Cookie("password",URLEncoder.encode(password,"utf-8"));
usernameCookie.setMaxAge(864000);
passwordCookie.setMaxAge(864000);//设置最大生存期限为10天
response.addCookie(usernameCookie);
response.addCookie(passwordCookie);
}
else
{
Cookie usernameCookie = new Cookie("username",username);
Cookie passwordCookie = new Cookie("password",password);
usernameCookie.setMaxAge(864000);
passwordCookie.setMaxAge(864000);//设置最大生存期限为10天
response.addCookie(usernameCookie);
response.addCookie(passwordCookie);
}
%>
<a href="users.jsp" target="_blank">查看用户信息</a>
</body>
</html>
举报