Servlet::Http::Cookie - HTTP cookie class
my $cookie = Servlet::Http::Cookie->new($name, $value);
my $clone = $cookie->clone();
my $comment = $cookie->getComment(); $cookie->setComment($comment);
my $domain = $cookie->getDomain(); $cookie->setDomain($domain);
my $seconds = $cookie->getMaxAge(); $cookie->setMaxAge($seconds);
my $name = $cookie->getName();
my $path = $cookie->getPath(); $cookie->setPath($path);
my $bool = $cookie->getSecure(); $cookie->setSecure($bool);
my $value = $cookie->getValue(); $cookie->setValue($value);
my $version = $cookie->getVersion(); $cookie->setVersion();
This class represents a cookie, a small amount of information sent by a servlet to a Web browser, saved by the browser, and later sent back to the server. A cookie's value can uniquely identify a client, so cookies are commonly used for session management.
A cookie has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, a maximum age, and a version number. Some Web browsers have bugs in how they handle the optional attributes, so use them sparingly to improve the interoperability of your servlets.
The servlet sends cookies to the browser by using the addCookie()
method, which adds fields to the HTTP response headers to send cookies
to the browser, one at a time. The browser is expected to support 20
cookies for each Web server, 300 cookies total, and may limit cookie
size to 4 KB each.
The browser returns cookies to the servlet by adding fields to HTTP
request headers. Cookies can be retrieved from a request by using the
getCookies()
method. Serveral cookies might have the same name but
different path attributes.
Cookies affect the caching of the Web pages that use them. HTTP 1.0 does not cache pages that use cookies created with this class. This class does not support the cache control defined with HTTP 1.1.
This class supports both the Version 0 (by Netscape) and Version 1 (by RFC 2109) cookie specifications. By default, cookies are created using Version 0 to ensure the best interoperability.
The name must conform to RFC 2109. That means it can contain only ASCII alphanumeric characters and cannot contain commas, semicolons, or white space or begin with a $ character. The cookie's name cannot be changed after creation.
The value can be anything the server chooses to send. Its value is
probably of interest only to the server. The cookie's value can be c
hanged after creation with setValue()
.
By deafult, cookies are created according to the Netscape cookie
specification. The version can be changed with setVersion()
.
Parameters:
Throws:
clone()
getComment()
getDomain()
getMaxAge()
getName()
getPath()
getSecure()
getValue()
getVersion()
setComment($comment)
Parameters:
setDomain($domain)
The form of the domain name is specified by RFC 2109. A domain name begins with a dot (.foo.com), which means that the cookie is visible to servers in that domain only (www.foo.com, but not www.bar.com). By default, cookies are only returned to the server that sent them.
Parameters:
setMaxAge($expiry)
A positive value indicates that the cookie will expire after that many seconds have passed. Note that the value is the maximum age when the cookie will expire, not the cookie's current age.
A negative value means that the cookie is not stored persistently and will be deleted when the client exits. A zero value causes the cookie to be deleted.
Parameters:
setPath($uri)
The cookie is visible to all the resources at or beneath the URI namespace specified by the path. A cookie's path must include the servlet that set the cookie in order to make the cookie visible to that servlet.
Parameters:
setSecure($flag)
Parameters:
setValue($value)
With version 0 cookies, values should not contain white space, brackets, parentheses, equals signs, commas, double quotes, slashes, question marks, at signs, colons and semicolons. The behavior of clients in response to empty values is undefined.
Parameters:
setVersion($number)
Parameters:
the Servlet::Util::Exception manpage
Brian Moseley, bcm@maz.org