HttpCookie SetDomain() Example

Specifies the domain within which this cookie should be presented.


HttpCookieclass SetDomain() method example. This example shows you how to use SetDomain() method.This method Specifies the domain within which this cookie should be presented.

Here is the code:-
/* 
 * @Program that Specifies the domain within which this cookie should be presented.
 * SetDomain.java 
 * Author:-RoseIndia Team
 * Date:-25-Jun-2008
 */

import java.net.*;

public class SetDomain {

    public static void main(String[] argsthrows Exception {
        String name = "Name";
        String value = "ABC";
        HttpCookie hc = new HttpCookie(name, value);

        //Returns the domain name set for this cookie.
        System.out.println("The domain name set is: " + hc.getDomain());
        //Specifies the domain within which this cookie should be presented.
        hc.setDomain(".com");
        System.out.println("The domain name set is: " + hc.getDomain());
    }
}

Output of the program:-
 The domain name set is: null
The domain name set is: .com

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

HOME | COPYRIGHT | CONTACT US