Import javax.servlet.http.cookie; import javax.servlet.http.httpservletResponse;
// Add cookie ... cookie namecookie = new cookie (constants.cookie_username, loginid); NameCookie.setMaxage (AutologyXpire); response.addcookie (NameCookie); ...
/ / Delete cookie ... cookie ... cookie (constants.cookie_username, ""); NameCookie.setMaxage (0); // delete this cookie response.addcookie (NameCookie);
Attachment knowledge:
You can set the living time of the cookie through the SetMaxage () method. If the survival time is a negative value, you will disappear when you turn off the cookie in the browser. The survival time is 0, and the representative deletes the cookie, the living time is positive, and how many seconds exist in cookies.
Client limits. A browser can create a cookie number up to 30, and each of the cookies that can not exceed 4KB, the total number of cookies that can be set for each Web site cannot exceed 20 (this has not been verified).