News:

MyKidsDiary.in :: Capture your kids magical moment and create your Online Private Diary for your kids

Main Menu

HttpCookie SetDomain() Example

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

Previous topic - Next topic

VelMurugan

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

Source : codingdiary