| java.lang.Object javax.servlet.http.Cookie
Cookie | public class Cookie implements Cloneable(Code) | | Encapsulates HTTP cookies.
Cookies are use to keep track of users for sessions and to
recognize users back for personalization.
When deleting cookies or changing the time, it's important to
set the same domain and path as originally passed. Browsers distinguish
cookies with different domain and path.
Cookie myCookie = new Cookie("mycookie", "myvalue");
myCookie.setPath("/path");
myCookie.setDomain("mydom.com");
// will live for a month
myCookie.setMaxAge(60 * 24 * 3600);
response.addCookie(myCookie);
To delete the above cookie, you'll need to do something like the
following:
Cookie myCookie = new Cookie("mycookie", "myvalue");
myCookie.setPath("/path");
myCookie.setDomain("mydom.com");
// kill the cookies
myCookie.setMaxAge(0);
response.addCookie(myCookie);
|
Constructor Summary | |
public | Cookie(String name, String value) Create a new cookie with the specified name and value. |
Cookie | public Cookie(String name, String value)(Code) | | Create a new cookie with the specified name and value.
Parameters: name - name of the cookie Parameters: value - value of the cookie |
clone | public Object clone()(Code) | | Returns a clone of the cookie
|
getComment | public String getComment()(Code) | | Gets the cookie comment
|
getDomain | public String getDomain()(Code) | | Returns the cookie's domain
|
getMaxAge | public int getMaxAge()(Code) | | Returns the max age of the cookie in seconds.
|
getName | public String getName()(Code) | | Returns the cookie's name.
|
getPath | public String getPath()(Code) | | Gets the URL path of a cookie.
|
getSecure | public boolean getSecure()(Code) | | Returns true if the cookie must be over a secure connection.
|
getValue | public String getValue()(Code) | | Returns the cookie's value.
|
getVersion | public int getVersion()(Code) | | Returns cookie protocol version.
|
setComment | public void setComment(String comment)(Code) | | Sets the cookie comment
Parameters: comment - comment string |
setDomain | public void setDomain(String domain)(Code) | | Sets the cookie domain. A site which uses multiple machines, e.g.
with DNS round robin, but a single site will want to set the domain.
cookie.setDomain("yahoo.com");
Parameters: domain - DNS domain name |
setMaxAge | public void setMaxAge(int maxAge)(Code) | | Sets the max age of a cookie. Setting maxAge to zero
deletes the cookie. Setting it to something large makes the cookie
persistent. If maxAge is not set, the cookie will only
last for the session.
Parameters: maxAge - lifetime of the cookie in seconds. |
setPath | public void setPath(String path)(Code) | | Sets the URL path of a cookie. Normally, cookies will just use
the root path.
|
setSecure | public void setSecure(boolean secure)(Code) | | Tells the browser that this cookie should only be passed over a
secure connection like SSL.
|
setValue | public void setValue(String value)(Code) | | Sets the cookie's value. Normally this will be a random unique
string to lookup the cookie in a database.
|
setVersion | public void setVersion(int version)(Code) | | Sets cookie protocol version, defaulting to 0.
|
toString | public String toString()(Code) | | Converts the cookie to a string for debugging.
|
|
|