一、java创建cookie

方法一:

Response.Cookies["userName"].Value = "patrick";

Response.Cookies["userName"].Expires = DateTime.Now.AddDays(1);

方法二:

HttpCookie aCookie = new HttpCookie("lastVisit");
aCookie.Value = DateTime.Now.ToString();
aCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(aCookie);

 

 

二、java读取cookie

获取value的值:request.cookie[“name”].value=? 
 
if(Request.Cookies["userName"] != null)
    Label1.Text = Server.HtmlEncode(Request.Cookies["userName"].Value);
 
if(Request.Cookies["userName"] != null)
{
    HttpCookie aCookie = Request.Cookies["userName"];
    Label1.Text = Server.HtmlEncode(aCookie.Value);
}

 

 

三、java销毁cookie

 

int counter;
if (Request.Cookies["counter"] == null)
    counter = 0;
else
{
    counter = int.Parse(Request.Cookies["counter"].Value);
}
counter++;
 
Response.Cookies["counter"].Value = counter.ToString();
Response.Cookies["counter"].Expires = DateTime.Now.AddDays(1); 



 

相关文章:

  • 2022-12-23
  • 2021-04-30
  • 2021-09-27
  • 2022-12-23
  • 2022-02-09
  • 2021-05-23
  • 2021-06-08
猜你喜欢
  • 2021-05-29
  • 2021-10-21
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案