Java,J2EE,Weblogic,Oracle

java项目随笔
随笔 - 90, 文章 - 6, 评论 - 61, 引用 - 0
数据加载中……

JAVA操作Cookie

写入 Cookie
          Cookie ckUserid = new Cookie("userid", Long.toString(bMember.getId()));
          //ckUserid.setMaxAge(86400);
          //ckUserid.setDomain("www.mangocity.com");
          //ckUserid.setPath("/MangoWeb;/TicketWeb;/CTIIWeb");
          ckUserid.setPath("/");
          response.addCookie(ckUserid);



读取 Cookie
         // 从Cookie中读取,看用户是否已经登陆
         Cookie[] cookies = request.getCookies();
         if (cookies != null) {
         for (int i = 0; i < cookies.length; i++) {
             if ("userid".equals(cookies[i].getName())) {
                 if ((cookies[i].getValue() != null) && (!"".equals(cookies[i].getValue()))) {
                  id = Long.parseLong(cookies[i].getValue());
                  bmember = _MemberDao.retrieveWebMember(id);
                   }
              }
          }
       }

posted on 2007-06-11 16:39 龚椿深 阅读(439) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: