code017.jsp
<%@ page import="java.net.URLDecoder"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>通过cookie保存并读取用户登录信息</title>
</head>
<body>
<%
Cookie[] cookies = request.getCookies();
String user = "";
String date = "";
if(cookies != null)
{
for(int i=0;i<cookies.length;i++)
{
if(cookies[i].getName().equals("mycookie"))
{
user = URLDecoder.decode(cookies[i].getValue().split("#")[0], "utf-8") ;
date = cookies[i].getValue().split("#")[1];
}
}
}
if("".equals(user) && "".equals(date))
{
%>
游客你好,欢迎您初次光临!
<form action="code018.jsp" method="post">
姓名:<input type="text" name="user" id="user" value="">
<input type="submit" name="submit" value="确定">
</form>
<%
}
else
{
%>
欢迎[<strong><%= user %></strong>再次光临]<br>
你的注册时间是:<%= date %>
<%
}
%>
</body>
</html>