Before adding the cookie to the outgoing headers, you can look up or set attributes of the cookie. Here’s a summary:
- getComment/setComment
- Gets/sets a comment associated with this cookie.
- getDomain/setDomain
- Gets/sets the domain to which cookie applies. Normally, cookies are returned only to the exact hostname that sent them. You can use this method to instruct the browser to return them to other hosts within the same domain. Note that the domain should start with a dot (e.g. .
prenhall.com), and must contain two dots for non-country domains like.com,.edu, and.gov, and three dots for country domains like.co.ukand.edu.es. - getMaxAge/setMaxAge
- Gets/sets how much time (in seconds) should elapse before the cookie expires. If you don’t set this, the cookie will last only for the current session (i.e. until the user quits the browser), and will not be stored on disk. See the
LongLivedCookieclass below, which defines a subclass ofCookiewith a maximum age automatically set one year in the future. - getName/setName
- Gets/sets the name of the cookie. The name and the value are the two pieces you virtually always care about. Since the
getCookiesmethod ofHttpServletRequestreturns an array ofCookieobjects, it is common to loop down this array until you have a particular name, then check the value with getValue. See thegetCookieValuemethod shown below. - getPath/setPath
- Gets/sets the path to which this cookie applies. If you don’t specify a path, the cookie is returned for all URLs in the same directory as the current page as well as all subdirectories. This method can be used to specify something more general. For example,
someCookie.setPath("/")specifies that all pages on the server should receive the cookie. Note that the path specified must include the current directory. - getSecure/setSecure
- Gets/sets the
booleanvalue indicating whether the cookie should only be sent over encrypted (i.e. SSL) connections. - getValue/setValue
- Gets/sets the value associated with the cookie. Again, the name and the value are the two parts of a cookie that you almost always care about, although in a few cases a name is used as a boolean flag, and its value is ignored (i.e the existence of the name means true).
- getVersion/setVersion
- Gets/sets the cookie protocol version this cookie complies with. Version 0, the default, adheres to the original Netscape specification. Version 1, not yet widely supported, adheres to RFC 2109



