Set the valid time for the cookie object, the Setmaxage () method can set the valid time for the cookie object.
For example: cookie C = new Cookie ("username", "John");
C.setmaxage (60);//60 the meaning of the second
C.setmaxage (60*60);//One Hour
C.setmaxage (365*24*60*60);//One year
If you do not set an expiration time, the cookie life cycle is the duration of the browser session, and the cookie disappears when the browser window is closed.
This lifetime is called a session cookie for browsing session cookies. Session cookies are generally not stored on the hard drive but are kept in memory.
If an expiration time is set, the browser saves the cookie to the hard disk and then opens the browser again after it is closed, and the cookies remain valid until the set expiration time is exceeded. Cookies stored on your hard disk can be shared between different browser processes, such as two IE windows. For cookies stored in memory, different browsers have different ways of handling them.
Cookie.setmaxage is set to 0 o'clock, the specified cookie is immediately removed from the browser
When Cookie.setmaxage is set to-1, the representative closes the current browser and fails.
This article on the life cycle of cookies is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud-dwelling community.