Name
Cookie
Synopsis
Class Name: javax.servlet.http.Cookie
Superclass: java.lang.Object
Immediate Subclasses: None
Interfaces Implemented: java.lang.Cloneable
Availability: New as of Servlet API 2.0; found in JSDK 2.0, JWS 1.1;
an earlier version previously in sun.* hierarchy
Description
The Cookie class provides an easy way for servlets
to read, create, and manipulate HTTP-style cookies, which allow
servlets to store small amounts of data on the client. Cookies are
generally used for session tracking or storing small amounts of
user-specific configuration information. For more information,
consult Chapter 7.
A servlet uses the getCookies() method of
HttpServletRequest to retrieve cookies submitted
as part of a client request. The addCookie()
method of HttpServletResponse sends a new cookie
to the browser. Because cookies are set using HTTP headers,
addCookie() must be called before any output is
sent to the client.
The original Servlet API 1.0 lacked this Cookie
class, although the Java Web Server included a Sun-specific
sun.servlet.util.Cookie class that worked in
roughly the same manner. The only significant difference is that the
retrieval and creation methods were static components of the
Cookie class itself, rather than being part of the
HttpServletRequest and
HttpServletResponse interfaces.
Class Summary
public class Cookie implements java.lang.Cloneable { // Constructors public Cookie(String name, String value); // Instance Methods public Object clone(); public String getComment(); ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access