How can I set a cookie that is persisted only for the duration of the client's session?

Govind Seshadri

You can create and set a cookie in the usual way. For example, if you are using a scriptlet, you can specify:

  Cookie aCookie = new Cookie("aName","aValue");

If you do not explicitly set a lifetime for the cookie using cookie.setMaxAge(), the cookie is automatically deleted when the user closes his browser.