标题:Cookie的应用,高手帮帮忙,好久都没测出来哦,先谢了
只看楼主
d7d7
Rank: 4
等 级:业余侠客
帖 子:91
专家分:210
注 册:2008-9-29
 问题点数:0 回复次数:0 
Cookie的应用,高手帮帮忙,好久都没测出来哦,先谢了
<%@page import = "javax.servlet.http.Cookie, java.util.*"%>
<title>cookie应用 </title>
<%
    String userName = "cookitest";
    Cookie[] cookie = request.getCookies();
    Cookie myCookie = null;
    List list = Arrays.asList(cookie);
    Iterator iterator = list.iterator();
   
    while(iterator.hasNext()) {
    Cookie temp = (Cookie)iterator.next();
        if(temp.getName().equals(userName + "access time" )) {
            myCookie = temp;
            break;
        }
    }
    out.println("当前时间为:" + new Date() + "<br>");
    if(myCookie != null) {
        out.println("上次访问的时间:" + myCookie.getValue());
        myCookie.setValue(new Date().toString());
    } else {
            myCookie = new Cookie(userName + " access time", new Date().toString);
    }
    response.addCookie(myCookie);
    response.flushBuffer();
%>
搜索更多相关主题的帖子: Cookie 应用 
2009-09-01 23:05



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-284461-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.180574 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved