HttpCookie SetSecure() Example

Indicates to the browser whether the cookie should only be sent using a secure protocol, such as HTTPS or SSL.


HttpCookieclass SetSecure() method example. This example shows you how to use SetSecure() method.This method Indicates to the browser whether the cookie should only be sent using a secure protocol, such as HTTPS or SSL.

Here is the code:-
/* 
 * @Program that Indicates to the browser whether the cookie should only be 
    sent using a secure protocol, such as HTTPS or SSL.
 * SetSecure.java 
 * Author:-RoseIndia Team
 * Date:-25-Jun-2008
 */

import java.net.*;

public class SetSecure {

    public static void main(String[] argsthrows Exception {
        String name = "Roseindia";
        String value = "ABC";
        HttpCookie hc = new HttpCookie(name, value);
        // Returns true if the browser is sending cookies only over a secure protocol
        System.out.println("Browser is sending cookies: " + hc.getSecure());
        //Indicates the browser whether the cookie should only be sent using a secure protocol    
        hc.setSecure(true);
        System.out.println("Browser is sending cookies: " + hc.getSecure());
    }
}

Output of the program:-
 Browser is sending cookies: false
Browser is sending cookies: true

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

HOME | COPYRIGHT | CONTACT US