• A cookie, also known as an HTTP cookie, web cookie, or browser cookie, is a piece of data stored by a website within a browser, and then subsequently sent back to the same website by the browser
  • Cookies were designed to be a reliable mechanism for websites to remember things that a browser had done there in the past

The following code shows how to create a new cookie

  • This code creates a cookie with a name of “username" and a value of “Jummy"
  • The cookie’s expiration date is set with the setMaxAge() method to 3,600 seconds from the time the browser receives the cookie
  • Method: setMaxAge (int age)
    age>0 : File cookie
    age<0 : Memory cookie
    age=0 : Delete cookie

The following code demonstrates how you would retrieve the value for a specific cookie

  • In the code, an array of cookies is retrieved from the HttpServletRequest object using the getCookies() method
  • The array is walked through until a cookie with the name of “user" is returned by the getName() method
  • Once the cookie is found, the getValue() method is called to retrieve the value of the cookie