A, cookie lifecycle
Set Cookie object effective time, setMaxAge () method can set the effective time of Cookie objects,
例如:Cookie c = new Cookie("username","john");
c.setMaxAge (60); // 60 seconds meaning
c.setMaxAge (60 * 60); // one hour
c.setMaxAge (365 * 24 * 60 * 60); // year
If you do not set an expiration time, it means that the cookie life cycle during a browsing session, simply close the browser window, cookie disappeared.
This period of life of the browsing session cookie is called a session cookie. General session cookie is not saved on the hard disk, but kept in memory.
If you set the expiration time, the browser cookie will be saved to your hard drive, open the browser again after closing, these cookie remain valid until the expiration time exceeds the set. cookie stored on the hard disk can be shared between different browser process, such as two IE windows. For cookie stored in memory, different browsers have different approach.
When cookie.setmaxage set to 0, will immediately delete the specified cookie on your browser
cookie.setmaxage set to -1, i.e., close the current browser on behalf of failure.
Two, Session life cycle
Although the session domain server, but the client browser needs to save sessionid, generally in the form cookie,
So session life cycle from the server-side session setup, the client cookie is valid both in terms of:
1. The session is valid from the server defaults to the last request / response transaction after 30 minutes (Tomcat), you can change and invalida () invalidate
2. The client's session cookie, cookie see the life cycle
Set Cookie object effective time, setMaxAge () method can set the effective time of Cookie objects,
例如:Cookie c = new Cookie("username","john");
c.setMaxAge (60); // 60 seconds meaning
c.setMaxAge (60 * 60); // one hour
c.setMaxAge (365 * 24 * 60 * 60); // year
If you do not set an expiration time, it means that the cookie life cycle during a browsing session, simply close the browser window, cookie disappeared.
This period of life of the browsing session cookie is called a session cookie. General session cookie is not saved on the hard disk, but kept in memory.
If you set the expiration time, the browser cookie will be saved to your hard drive, open the browser again after closing, these cookie remain valid until the expiration time exceeds the set. cookie stored on the hard disk can be shared between different browser process, such as two IE windows. For cookie stored in memory, different browsers have different approach.
When cookie.setmaxage set to 0, will immediately delete the specified cookie on your browser
cookie.setmaxage set to -1, i.e., close the current browser on behalf of failure.