Class Cookie

java.lang.Object
jodd.http.Cookie

public class Cookie extends Object
Cookie object. Simple cookie data holder, cookie header parser and generator.
  • Field Details

    • name

      private String name
    • value

      private String value
    • comment

      private String comment
    • domain

      private String domain
    • maxAge

      private Integer maxAge
    • expires

      private String expires
    • path

      private String path
    • secure

      private boolean secure
    • version

      private Integer version
    • httpOnly

      private boolean httpOnly
  • Constructor Details

    • Cookie

      public Cookie(String name, String value)
      Creates cookie with specified name and value.

      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 value can be anything the server chooses to send.

    • Cookie

      public Cookie(String cookie)
      Parses cookie data from given user-agent string.
  • Method Details

    • setName

      private void setName(String name)
      Sets the cookie name and checks for validity.
    • getComment

      public String getComment()
      Returns the comment describing the purpose of this cookie, or null if the cookie has no comment.
    • setComment

      public Cookie setComment(String purpose)
      Specifies a comment that describes a cookie's purpose. The comment is useful if the session presents the cookie to the user.
    • getDomain

      public String getDomain()
      Returns the domain name set for this cookie. The form of the domain name is set by RFC 2109.
    • setDomain

      public Cookie setDomain(String pattern)
      Specifies the domain within which this cookie should be presented.

      The form of the domain name is specified by RFC 2109. A domain name begins with a dot (.foo.com) and means that the cookie is visible to servers in a specified Domain Name System (DNS) zone (for example, www.foo.com, but not a.b.foo.com). By default, cookies are only returned to the server that sent them.

    • getMaxAge

      public Integer getMaxAge()
      Returns the maximum age of the cookie, specified in seconds, By default, -1 indicating the cookie will persist until session shutdown.
    • setMaxAge

      public Cookie setMaxAge(int expiry)
      Sets the maximum age of the cookie in seconds.

      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 Web session exits. A zero value causes the cookie to be deleted.

    • getPath

      public String getPath()
      Returns the path on the server to which the session returns this cookie. The cookie is visible to all subpaths on the server.
    • setPath

      public Cookie setPath(String uri)
      Specifies a path for the cookie to which the client should return the cookie.

      The cookie is visible to all the pages in the directory you specify, and all the pages in that directory's subdirectories. A cookie's path must include the servlet that set the cookie, for example, /catalog, which makes the cookie visible to all directories on the server under /catalog.

      Consult RFC 2109 (available on the Internet) for more information on setting path names for cookies.

    • isSecure

      public boolean isSecure()
      Returns true if the session is sending cookies only over a secure protocol, or false if the session can send cookies using any protocol.
    • setSecure

      public Cookie setSecure(boolean flag)
      Indicates to the session whether the cookie should only be sent using a secure protocol, such as HTTPS or SSL.
    • getName

      public String getName()
      Returns the name of the cookie. The name cannot be changed after creation.
    • getValue

      public String getValue()
      Returns the value of the cookie.
    • setValue

      public Cookie setValue(String newValue)
      Assigns a new value to a cookie after the cookie is created. If you use a binary value, you may want to use BASE64 encoding.
    • getVersion

      public Integer getVersion()
      Returns the version of the protocol this cookie complies with. Version 1 complies with RFC 2109, and version 0 complies with the original cookie specification drafted by Netscape. Cookies provided by a session use and identify the session's cookie version.
    • setVersion

      public Cookie setVersion(int version)
      Sets the version of the cookie protocol this cookie complies with. Version 0 complies with the original Netscape cookie specification. Version 1 complies with RFC 2109.
    • isHttpOnly

      public boolean isHttpOnly()
    • setHttpOnly

      public Cookie setHttpOnly(boolean httpOnly)
    • getExpires

      public String getExpires()
    • setExpires

      public Cookie setExpires(String expires)
    • toString

      public String toString()
      Overrides:
      toString in class Object