The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.
See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.
Though you are probably already familiar with cookies, you might not know how to take advantage of them in your Java application. This lesson guides you through the concept of cookies and explains how to set a cookie handler so that your HTTP URL connections will use it.
Java SE provides one main class for this functionality,
java.net.CookieHandler
, and the following supporting classes and interfaces:
java.net.CookieManager
,
java.net.CookiePolicy
,
java.net.CookieStore
, and
java.net.HttpCookie
.
This page describes cookies and explains how they are used to provide sessions.
This page explains how a cookie handler is called when you access a web site and how to set a cookie handler.
Java SE provides a default cookie handler implementation that is sufficient in most cases and highly customizable.
Here are some examples of how to customize the cookie policy and write your own cookie store.