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
|