Cookies

In this chapter you will learn:

  1. List All Cookies

List All Cookies

import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.CookiePolicy;
import java.net.HttpCookie;
import java.net.URL;
import java.util.List;
//from   j a  va  2  s .  c om
public class Main {
  public static void main(String[] args) throws Exception {
    CookieManager cm = new CookieManager();
    cm.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cm);

    new URL("http://google.com").openConnection().getContent();

    List<HttpCookie> cookies = cm.getCookieStore().getCookies();
    for (HttpCookie cookie : cookies) {
      System.out.println("Name = " + cookie.getName());
      System.out.println("Value = " + cookie.getValue());
      System.out.println("Lifetime (seconds) = " + cookie.getMaxAge());
      System.out.println("Path = " + cookie.getPath());
      System.out.println();
    }
  }
}

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. What is a generic type
  2. A Generic Class with Two Type Parameters
  3. What is the syntax for declaring a generic class
Home » Java Tutorial » Socket

Socket

    Socket
    Socket creation
    Socket read
    HTTP client
    SMTP Client
    Cipher Socket
    Socket connection and thread

ServerSocket

    ServerSocket
    ServerSocket connection
    File server and client
    Thread based Server
    Time server
    SocketServer based zip server
    ServerSocketChannel
    Channel selector

SocketChannel

    SocketChannel Creation
    Read and write with SocketChannel
    SocketChannel based HTTP client
    SocketChannel Asynchronous

ServerSocketChannel

    ServerSocketChannel
    Channel selector

SSL

    SSL Client Socket
    SSL Server Socket

UDP

    DatagramSocket
    DatagramChannel
    Multicast Group

Cookie

    Cookies