On Wed, 24 May 2000, Andy Dingfelder wrote:

> Yea, I read that too, and it confused me. The reason that it
> confused me to say that "The get methods are rarely used" is because
> the get methods are then used 2 pages later.  (getCookies, getName &
> getValue)
>
> If we are not supposed to get the cookies, what use is there to
> setting them ?
>
> Maybe i'm missing something here...
[ ... ]

Yes, you are.  The get methods he is referring to (the ones that are
rarely used) are the ones that get the specific Cookie attributes that
are not typically passed to the server, like getMaxAge, getComment,
getDomain, etc.  getCookies is used to get the array of Cookies, not
any attribute on a specific Cookie.  getName and getValue are OK
because that Cookie information is available to the server (similar
with getVersion).


> -----Original Message-----
> From: A mailing list for discussion about Sun Microsystem's Java Servlet
> API Technology. [mailto:[EMAIL PROTECTED]]On Behalf Of Milt
> Epstein
> Sent: Tuesday, May 23, 2000 7:53 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Cookie Problem
>
>
> On Thu, 18 May 2000, Andy Dingfelder wrote:
>
> > 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 ?
>
> I thought I remembered reading something in Jason Hunter's Java
> Servlet Programming book that was relevant here, and I just confirmed
> it.  On page 203, in the section on "Persistent Cookies", subsection
> on "Working with Cookies", it says:
>
>   You can set a number of attributes for a cookie in addition to its
>   name and value.  The following methods are used to set these
>   attributes.  As you can see in Appendix B, HTTP Servlet API Quick
>   Reference, there is a corresponding get method for each set method.
>   The get methods are rarely used, however, because when a cookie is
>   sent to the server, it contains only its name, value, and version.
>
>
> > -----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
> >
>
> Milt Epstein
> Research Programmer
> Software/Systems Development Group
> Computing and Communications Services Office (CCSO)
> University of Illinois at Urbana-Champaign (UIUC)
> [EMAIL PROTECTED]
>
> ___________________________________________________________________________
> 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
>
> ___________________________________________________________________________
> 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
>

Milt Epstein
Research Programmer
Software/Systems Development Group
Computing and Communications Services Office (CCSO)
University of Illinois at Urbana-Champaign (UIUC)
[EMAIL PROTECTED]

___________________________________________________________________________
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