当前位置:网站首页>Cookie operation

Cookie operation

2022-07-05 07:20:00 Sun Tianyang

1. take cookie Back to the browser
// Create a Cookie
Cookie cookie = new Cookie(“cookieName”);
// Settings are readable only by browsers
cookie.setHttpOnly(true);
// Set retention duration -1 Means not to delete
cookie.setMaxAge(-1);
// Set up cookie Reserved path , It can be shared in the same application server
cookie.setPath("/")
response.addCookie(cookie);
2. obtain cookie
Cookie[] cookies = request.getCookie();
if(cookies == null || cookies.length == 0) {
return null;
}
for(Cookie cookie : cookies) {
if(“cookieName”.equals(cookie.getName())) {
return cookie.getValue();
}
}
return null;

原网站

版权声明
本文为[Sun Tianyang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140557104546.html