Return to Snippet

Revision: 3667
at August 30, 2007 06:51 by jsbournival


Updated Code
// retrieve cookies
Cookie[] cookies = request.getCookies();

for(int i=0; i < cookies.length; i++) {
    Cookie c = cookies[i];

    if (c.getName().equals("theCookieImLookingFor")) {
        String cookieValue = c.getValue();
    }
}

// ...

// set a new cookie
Cookie myCookie = new Cookie("name", "value"); 
response.addCookie(myCookie);

Revision: 3666
at August 30, 2007 06:45 by jsbournival


Updated Code
// retrieve cookies
Cookie[] cookies = request.getCookies();

for(i=0; i < cookies.length; i++) {
    Cookie c = cookies[i];

    if (c.getName().equals("theCookieImLookingFor")) {
        String cookieValue = c.getValue();
    }
}

// ...

// set a new cookie
Cookie myCookie = new Cookie("name", "value"); 
response.addCookie(myCookie);

Revision: 3665
at August 30, 2007 06:42 by jsbournival


Initial Code
Cookie myCookie = new Cookie("name", "value"); 
response.addCookie(myCookie);

Initial URL
http://www.commentcamarche.net/servlets/servcookie.php3

Initial Description
Simple snippet on how to get/set a cookie

Initial Title
get/set Cookies

Initial Tags
java

Initial Language
Java