HttpCookie SetDiscard() Example

Specify whether user agent should discard the cookie unconditionally.


HttpCookieclass SetDiscard() method example. This example shows you how to use SetDiscard() method.This method Specify whether user agent should discard the cookie unconditionally.

Here is the code:-
/* 
 * @Program that Specify whether user agent should discard the cookie unconditionally.
 * SetDiscard.java 
 * Author:-RoseIndia Team
 * Date:-25-Jun-2008
 */

import java.net.*;

public class SetDiscard {

    public static void main(String[] argsthrows Exception {
        String name = "Name";
        String value = "ABC";
        HttpCookie hc = new HttpCookie(name, value);
        //Return the discard attribute of the cookie
        System.out.println("Discard attribute of the cookie is :" + hc.getDiscard());
        //Specify whether user agent should discard the cookie unconditionally.
        hc.setDiscard(true);
        System.out.println("Discard attribute of the cookie is :" + hc.getDiscard());
    }
}

Output of the program:-
Discard attribute of the cookie is :false
Discard attribute of the cookie is :true

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US