import java.net.HttpCookie;
public class JavaHttpCookieSetHttpOnlyExample1 {
public static void main(String[] args) {
HttpCookie cookie = new HttpCookie("Student", "1");
// Indicate whether the cookie can be considered as HTTP Only or not.
cookie.setHttpOnly(true);
// Return true if the cookie is considered as HTTPOnly.
System.out.println("Check whether the cookie is HTTPOnly: "+cookie.isHttpOnly());
Check whether the cookie is HTTPOnly: true
import java.net.HttpCookie;
public class JavaHttpCookieSetHttpOnlyExample2 {
public static void main(String[] args) {
HttpCookie cookie = new HttpCookie("Student", "1");
// Indicate whether the cookie can be considered as HTTP Only or not.
cookie.setHttpOnly(false);
// Return false if the cookie is not considered as HTTPOnly.
System.out.println("Check whether the cookie is HTTPOnly: "+cookie.isHttpOnly());
Check whether the cookie is HTTPOnly: false
import java.net.HttpCookie;
public class JavaHttpCookieSetHttpOnlyExample3 {
public static void main(String[] args) {
HttpCookie cookie1 = new HttpCookie("Student1", "1");
HttpCookie cookie2 = new HttpCookie("Student2", "2");
//Indicate whether the cookie can be considered as HTTP Only or not.
cookie1.setHttpOnly(true);
cookie2.setHttpOnly(false);
System.out.println("Check whether the first cookie is HTTPOnly:"+cookie1.isHttpOnly());
System.out.println("Check whether the second cookie is HTTPOnly:"+cookie2.isHttpOnly());
Check whether the first cookie is HTTPOnly:true Check whether the second cookie is HTTPOnly:false