java.net.CookieHandler Class in Java Last Updated : 10 Mar, 2021 Comments Improve Suggest changes Like Article Like Report The object of the CookieHandler Class in Java provides a callback mechanism for hooking up an HTTP state management policy implementation into the HTTP protocol handler. The mechanism of how to make HTTP requests and responses is specified by the HTTP state management mechanism. A system-wide CookieHandler that too employed by the HTTP protocol handler is often registered by doing a CookieHandler.setDefault(CookieHandler). The currently registered CookieHandler are often retrieved by calling CookieHandler.getDefault(). Declaration: public abstract class CookieHandler extends ObjectConstructor: CookieHandler(); Example: Java // Java program to demonstrate the usage // of CookieHandler Class import java.net.CookieHandler; import java.net.CookieManager; import java.net.CookieStore; import java.net.HttpCookie; import java.net.URL; import java.net.URLConnection; import java.util.List; public class JavaCookieHandlerExample1 { public static void main(String args[]) throws Exception { String uri = "https://www.google.com"; // Instantiate CookieManager; CookieManager c = new CookieManager(); // First set the default cookie manager. CookieHandler.setDefault(c); URL url = new URL(uri); // All the following subsequent URLConnections // will use the same cookie manager. URLConnection connection = url.openConnection(); connection.getContent(); // Get cookies from underlying CookieStore CookieStore cookieStore = c.getCookieStore(); List<HttpCookie> cookieList = cookieStore.getCookies(); for (HttpCookie cookie : cookieList) { // Get domain set for the cookie System.out.println("The domain is: " + cookie.getDomain()); } } } Output: The domain is: .google.comThe CookieHandler class provides the following methods in Java: MethodDescriptionget(URI uri, Map<String, List<String> >requestHeaders)This method gets all the applicable cookies from a cookie cache for the specified URI in the request header.getDefault()This method gets the system-wide cookie handler.put(URI uri, Map<String, List<String> > responseHeaders)This method sets all the applicable cookies, examples are response header fields that are named Set-Cookie2, present in the response headers into a cookie cache.setDefault(CookieHandler cHandler)This method sets or unsets the system-wide cookie handler. Comment More infoAdvertise with us Next Article java.net.CookieHandler Class in Java S surbhityagi15 Follow Improve Article Tags : Java Technical Scripter Technical Scripter 2020 Java-net-package Practice Tags : Java Similar Reads java.net.CookieManager Class in Java The CookieManager class provides a precise implementation of CookieHandler. This separates the storage of cookies from the policy surrounding accepting and rejecting cookies. A CookieManager is initialized with a CookieStore and a CookiePolicy. The CookieStore manages storage, and the CookiePolicy o 4 min read java.net.CookieStore Class in Java A CookieStore is an interface in Java that is a storage area for cookies. It is used to store and retrieve cookies. A CookieStore is responsible for removing HTTPCookie instances that have expired. The CookieManager adds the cookies to the CookieStore for every incoming HTTP response by calling Cook 4 min read java.net.CookiePolicy Class in Java CookiePolicy implementations decide which cookies should be accepted and which should be rejected. Three pre-defined policy implementations are provided, namely ACCEPT_ALL, ACCEPT_NONE, and ACCEPT_ORIGINAL_SERVER. Signaturepublic interface CookiePolicyFields S.NO Field Description Data Type 1.ACCEPT 2 min read Javax.servlet.http.Cookie class in Java Many websites use small strings of text known as cookies to store persistent client-side state between connections. Cookies are passed from server to client and back again in the HTTP headers of requests and responses. Cookies can be used by a server to indicate session IDs, shopping cart contents, 7 min read java.net.URL Class in Java URL is an acronym of Uniform resource locator. It is a pointer to locate resource in www (World Wide Web). A resource can be anything from a simple text file to any other like images, file directory etc. The typical URL may look like http://www.example.com:80/index.htmlThe URL has the following part 4 min read Like