<%@ page contentType="text/html; charset=GB2312"
        import="java.util.*"%>
<html>

<head>
<title>cookie 用户登录次数</title>
</head>
<body>
<center>

<font size = 5 color = blue>cookie 用户登录次数</font>
</center>
<hr><p></p>
<%
Cookie temp = null;
int cookielen = cookies.length;
int count=1;
//取得cookie变数阵列的长度
 
if(cookielen != 0) //判断是否成功取得cookie资料

{     
       for (int i = 0; i < cookielen; i++)
       {                   temp = cookies[i]; //取得cookies数组中的Cookie变量
                            
              if (temp.getName().equals("accessCount"))

              { 
              	count=Integer.perseInt(temp.getValue());//获取登录页面次数
              }

       }
}
 %>
 通过这个浏览器<font color = blue></font>
 您的登录次数是<font color = red>
   <%= count %>
   </font><br>
 <%
  
Cookie accessCount = new Cookie("accessCount", String.valueOf(count+1));
 response.addCookie(accessCount); //将更新后的数据存入cookie变数加入cookie中，存在客户端
%>
</body>
</html>
