struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robin Whitley <rwhit...@silverstream.com>
Subject Trouble with setting and retrieving cookie values
Date Mon, 01 Oct 2001 16:40:36 GMT
I am having a problem with setting and retrieving cookies within an action
class.  From a servlet with a simple test I can set and retrieve cookie
values, with the example code below:

Setting the cookie:

Cookie c = new Cookie("test", "testvalue");
            c.setMaxAge(60*60*24*90);
            c.setPath("/");
            res.addCookie(c);

Retrieving the cookie:

 Cookie[] cookies = request.getCookies();
 if (cookies != null && cookies.length > 0) { // Cookie(s) found
      for (int i = 0; i < cookies.length; i++) {
           if ((cookies[i].getName()).equals("test")) {
               cookievalue = cookies[i].getValue();
            }
        }
}

As soon as I put the code in an action class and I either forward, or
redirect to a jsp, the cookie information is not saved.  Does anyone have
any clues as to why the same code is not working within the action class?
Any help would be appreciated.


Robin Whitley

Mime
View raw message