原本以为还算简单的一个功能,但还是让初学者的我花费了不少时间.
先看代码:
1.初始登录页面
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
/* 关于记住密码的验证 */
String name = "";
String password = "";
Cookie[] cookies = request.getCookies();
for (Cookie cookie : cookies) {
/* 只有在index页面选中了记住密码,就可以在remembercookie页面创建cookie并存储数据,在这里就可以获取数据 */
if ("uname".equals(cookie.getName())) {;
name = cookie.getValue();
} else if ("password".equals(cookie.getName())) {
password = cookie.getValue();
}
}
%>
<form action="rememberCookie.jsp" method="post">
用户名: <input type="text" name="un