News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

HttpCookie SetDiscard() Example

Started by VelMurugan, Dec 20, 2008, 10:41 PM

Previous topic - Next topic

VelMurugan

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[] args) throws 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

Source : codingdiary