Here is how I am setting the cookie:

        java.io.PrintWriter out = response.getWriter();
        Cookie[] cookies = request.getCookies();
        int secs = 2 * 24 * 60 * 60; // 2 days
        out.println("setting cookie: " + cookieName + "to: " + cookieVal + "<p>" +
                         "(expires in )" + secs + "seconds)");
        Cookie cookie = new Cookie(cookieName, cookieVal);
        cookie.setMaxAge(secs);
        response.addCookie(cookie);

Here is How I am reading all of the cookies:

                        out.println("trying to list all cookies<p>");
                        if ((cookies == null) || (cookies.length == 0))
                        {
                            out.println("No Cookies are present.<p>");
                        }
                        else
                        {
                            // iterate through all the cookes & print each one
                            for (int i = 0; i < cookies.length; i++)
                            {
                                Cookie cookie = cookies[i];
                                out.println("Cookie Name: " + cookie.getName() + 
"<br>");
                                out.println("\tCookie Value: " + cookie.getValue() +
                                            "(age = "+ cookie.getMaxAge() + 
")<br><br>");
                            }
                        }

It looks ok to me...   any ideas ?


-----Original Message-----
From: Kevin Mukhar [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 17, 2000 5:29 PM
To: Andrew Dingfelder
Subject: Re: Cookie Problem


Andrew Dingfelder wrote:
>
> I am having a little trouble setting cookies from my
> servlet.
> I have a test web page where you can see the symptoms:
> http://24.25.16.175:8080/cookie.html
>
> When I set the cookie, I am giving it a maxAge of
> 172800 (2 days worth of seconds).
>
> When I read the cookie to display it, it says that the
> maxAge is -1 (which I believe means that the cookie
> only lasts as long as the browser session)

You'll probably need to post code. It seems to be working for me.

You are correct that pressing "List Cookie" or "List All Cookies" is showing a
Max Age of -1, but that appears to be an error in your servlet.

I set a cookie, and then exited my browser completely. Here's the cookie from my
cookies.txt file:

24.25.16.175:8080       FALSE   /servlet        FALSE   958771554       myname  myname


958771554 corresponds to Fri May 19 21:25:54 2000, 2 days after I set the
cookie.

K Mukhar

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to