8.4. Examples of Setting and Reading Cookies

Listing 8.1 and Figure 8-1 show the SetCookies servlet, a servlet that sets six cookies. Three have the default expiration date, meaning that they should apply only until the user next restarts the browser. The other three use setMaxAge to stipulate that they should apply for the next hour, regardless of whether the user restarts the browser or reboots the computer to initiate a new browsing session.

Figure 8-1. Result of SetCookies servlet.

Listing 8.2 shows a servlet that creates a table of all the cookies sent to it in the request. Figure 8-2 shows this servlet immediately after the SetCookies servlet ...

Get Core Servlets and JavaServer Pages™ now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.