Cookies
In this chapter you will learn:
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:
- What is a generic type
- A Generic Class with Two Type Parameters
- What is the syntax for declaring a generic class
Home » Java Tutorial » Socket