#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    1
    Rep Power
    0

    JSP: cookie.getMaxAge() doesn't seem to work properly


    This JSP code doesn't return the same Max age. Any idea why, and how can I fix that?


    Cookie cookie = new Cookie("test", "some value");
    cookie.setMaxAge(86400);
    response.addCookie(cookie);
    try
    {
    Cookie[] cookies = request.getCookies();
    for (int i=0; i<cookies.length; i++)
    {
    if (cookies[i].getName().equals("test"))
    {
    out.print("1st result:"+ cookies[i].getValue() +"___"+ cookies[i].getMaxAge() +"<br />");
    }
    }
    out.print("2nd result:"+ cookie.getValue() +"___"+ cookie.getMaxAge() +"<br />");
    }
    catch(Exception e)
    {
    }


    Result is:
    1st result:some value___-1
    2nd result:some value___86400
    Last edited by t360; May 15th, 2003 at 11:01 PM.

IMN logo majestic logo threadwatch logo seochat tools logo