Chinaunix首页 | 论坛 | 博客
  • 博客访问: 131659
  • 博文数量: 17
  • 博客积分: 2510
  • 博客等级: 少校
  • 技术积分: 320
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-28 10:38
文章分类

全部博文(17)

文章存档

2009年(1)

2008年(16)

我的朋友

分类: Java

2009-01-16 17:53:21

添加cookie

   Cookie addMyCookie = new Cookie("usID",234234);  

    addMyCookie.setMaxAge(-1); //  60*60*24*365 cookie 的对大有效期,秒为单位

  1. addMyCookie.setDomain("XXXX.com");   
  2. addMyCookie.setPath("/");   
  3. response.addCookie(addMyCookie);  

//----------------------------------------------------------

public class CookieValue
{
              private CookieValue()
              {}
              public string username;
              public string usercard;
              public string userid

              public static CookieValue   GetInstanceFromCookie(string cookiename)
              {
                        CookieValue value = null;
                        HttpCookie cookie = HttpContext.Current.Request.Cookies[cookiename];
                        if(cookie != null)
                        {
                                  value = new CookieValue();
                                  value.username = cookie.Values[ "username "];
                                  ......以下相同复制另两个字段
                                  return value;
                        }
                        return value;
              }
}

---------调用
CookieValue value = CookieValue.GetInstanceFromCookie(cookie名);

//---------------------------------------------------------------

  1. Cookie[] cookies = request.getCookies();   
  2.     if (cookies != null){   
  3.            for(int i=0;i
  4.                    Cookie c = cookies[i];   
  5.                    if(c.getName().equals("usID")){   
  6.                        checkCookie = true;   
  7.             }   
  8.      }   
阅读(1101) | 评论(0) | 转发(0) |
0

上一篇:div 页面元素居中

下一篇:没有了

给主人留下些什么吧!~~