Creating and deleting cookies in Java

Time:2021-7-22

//Write cookie operation
Cookie cooki;
cooki=new Cookie(“bbs_ 0001”,String.valueOf(num));// User ID
cooki.setMaxAge(60*60*24*365);// Cookie time
cooki.setPath(“/”); // According to the needs of the individual, it can be created in the path of different functions
response.addCookie(cooki);
//Empty cookie operation
Cookie[] cookies=request.getCookies();
try
{
for(int i=0;i<cookies.length;i++)
{
Cookie cookie = new Cookie(“bbs_0001”,null);
cookie.setMaxAge(0);
//cookie.setPath(“/”);// Fill in according to the path where you created the cookie
response.addCookie(cookie);
}
}catch(Exception ex)
{
Out. Println (“exception occurred in clearing cookies!”);
}
Add session
session.setAttribute(“isSessionLogin”,name);
Delete session
session.removeAttribute(“isSessionLogin”);

Recommended Today

Implementation example of go operation etcd

etcdIt is an open-source, distributed key value pair data storage system, which provides shared configuration, service registration and discovery. This paper mainly introduces the installation and use of etcd. Etcdetcd introduction etcdIt is an open source and highly available distributed key value storage system developed with go language, which can be used to configure sharing […]