将cookie保存到客户端
login.jsp
<%@page import="org.apache.tomcat.util.http.Cookies"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%! //定义全局变量
String uname;
%>
<%
Cookie[] cookies=request.getCookies();
for(Cookie cookie:cookies){
if(cookie.getName().equals("uname")){
uname=cookie.getValue();
}
}
%>
<form action="" method="post">
<!--默认是get提交方式,method="get"-->
用户名:<input type="text" name="uname" value="<%=(uname==null?"":uname)%>"><br>
密码:<input type="password" name="upwd"><br>
<input type="submit" value="登陆">
</form>
</body>
</html>