HttpCookie SetPath() Example

Specifies a path for the cookie to which the client should return the cookie.


HttpCookieclass SetPath() method example. This example shows you how to use SetPath() method.This method Specifies a path for the cookie to which the client should return the cookie.

Here is the code:-
/* 
 * @Program that Specifies a path for the cookie to which the client should 
return the cookie
 * SetPath.java 
 * Author:-RoseIndia Team
 * Date:-25-Jun-2008
 */

import java.net.*;

public class SetPath {

    public static void main(String[] argsthrows Exception {
        String name = "Roseindia";
        String value = "ABC";
        HttpCookie hc = new HttpCookie(name, value);
        //Returns the path on the server to which the browser returns this cookie.
        System.out.println("Path to which browser returns this cookie is: " + hc.getPath());
        hc.setPath("http://java.sun.com/javase/6/docs/api/");
        //Specifies a path for the cookie to which the client should return the cookie
        System.out.println("Path to which browser returns this cookie is: " + hc.getPath());

    }
}

Output of the program:-
 Path to which browser returns this cookie is: null
Path to which browser returns this cookie is: http://java.sun.com/javase/6/docs/api/

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

HOME | COPYRIGHT | CONTACT US