java中如何获取cookie对象中的值

java中如何获取cookie对象中的值,第1张

 // 获取request里面的cookie cookie里面存值方式也是 键值对的方式 

Cookie[] cookie = requestgetCookies();

for (int i = 0; i < cookielength; i++) {

Cookie cook = cookie[i];

if(cookgetName()equalsIgnoreCase("eredg4loginaccount")){ //获取键 

Systemoutprintln("account:"+cookgetValue()toString());    //获取值 

}

}

<!DOCTYPE HTML>

<html lang="en-US">

<head>

<meta charset="UTF-8">

<meta name="keywords" content="白菜编辑部">

<title>白菜编辑部</title>

<style type="text/css">

</style>

<script type="text/javascript">

function readCookie (name)

{

var cookieValue = "";

var search = name + "=";

if (documentcookielength > 0)

{

offset = documentcookieindexOf (search);

if (offset != -1)

{

offset += searchlength;

end = documentcookieindexOf (";", offset);

if (end == -1)

end = documentcookielength;

cookieValue = unescape (documentcookiesubstring (offset, end))

}

}

return cookieValue;

}

function writeCookie (name, value, hours)

{

var expire = "";

if (hours != null)

{

expire = new Date ((new Date ())getTime () + hours 3600000);

expire = "; expires=" + expiretoGMTString ();

}

documentcookie = name + "=" + escape (value) + expire;

}

writeCookie ("myCookie", "my name", 24);

alert (readCookie ("myCookie"));

</script>

</head>

<body>

</body>

</html>

name:cookie名称

value:cookie值

expire:cookie有效时间

path:存储路径

domain:域

setcookie(name, value, expire, path, domain);

// 打印一个cookie

echo $_COOKIE["name"];

// 打印所有cookie

print_r($_COOKIE);

以上就是关于java中如何获取cookie对象中的值全部的内容,包括:java中如何获取cookie对象中的值、如何使用js来获取cookie的值、php获取当前域名下的所有cookie等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/9453121.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-28
下一篇 2023-04-28

发表评论

登录后才能评论

评论列表(0条)

保存