HttpCookie SetMaxAge() Example

Sets the maximum age of the cookie in seconds.


HttpCookieclass SetMaxAge() method example. This example shows you how to use SetMaxAge() method.This method Sets the maximum age of the cookie in seconds.

Here is the code:-
/* 
 * @Program that Sets the maximum age of the cookie in seconds.
 * SetMaxAge.java 
 * Author:-RoseIndia Team
 * Date:-25-Jun-2008
 */

import java.net.*;

public class SetMaxAge {

    public static void main(String[] argsthrows Exception {
        String name = "Name";
        String value = "ABC";
        HttpCookie hc = new HttpCookie(name, value);
        //Returns the maximum age of the cookie, specified in seconds.
        System.out.println("Maximum age of the cookie is: " + hc.getMaxAge());

        //Sets the maximum age of the cookie in seconds.
        hc.setMaxAge(2345);
        System.out.println("Maximum age of the cookie is: " + hc.getMaxAge());
    }
}

Output of the program:-
 Maximum age of the cookie is: -1
Maximum age of the cookie is: 2345

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

HOME | COPYRIGHT | CONTACT US