You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Paul Wallace <pa...@mustang-technologies.com> on 2002/03/11 04:58:56 UTC

cookie retrieval II

Hello Everyone,
    Similar to a previous posting, I have some code to make a cookie:

Cookie cook = new Cookie("memberCookie", userid);
cook.setPath("/mydir");
response.addCookie(cook);

and to retreive the cookie:

Cookie cookies[] = request.getCookies();
for(int i = 0; i < cookies.length; i++) {
     if (cookies[i].getName().equals("memberCookie")); {
    out.println("Welcome: " + cookies[i].getValue() + "<p>");
    }
 }

to retrieve the cookie. It retrieves the value but with an additional
nuisance. I get the desired cookie, but also what appears to be the session
ID (output below).

Welcome: paul
Welcome: 61D0D4C3E11302B07308C3D960D13840

I am obviously looping through the length of the cookies array, retrieving
the value, but also this unwanted text. What can I do to retrieve just the
value please? It looks like my if condition is being satisified twice?!

Frustrated

Paul.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: cookie retrieval II

Posted by David Shanahan <da...@biosjp.com>.
>      if (cookies[i].getName().equals("memberCookie")); {
It looks like the problem is the semicolon after the "if()"  ^
This code will print out all the cookies, not just the "memberCookie".

----- Original Message -----
From: "Paul Wallace" <pa...@mustang-technologies.com>
To: "Tomcat Developers List" <to...@jakarta.apache.org>
Sent: Monday, March 11, 2002 12:58 PM
Subject: cookie retrieval II


> Hello Everyone,
>     Similar to a previous posting, I have some code to make a cookie:
>
> Cookie cook = new Cookie("memberCookie", userid);
> cook.setPath("/mydir");
> response.addCookie(cook);
>
> and to retreive the cookie:
>
> Cookie cookies[] = request.getCookies();
> for(int i = 0; i < cookies.length; i++) {
>      if (cookies[i].getName().equals("memberCookie")); {
>     out.println("Welcome: " + cookies[i].getValue() + "<p>");
>     }
>  }
>
> to retrieve the cookie. It retrieves the value but with an additional
> nuisance. I get the desired cookie, but also what appears to be the
session
> ID (output below).
>
> Welcome: paul
> Welcome: 61D0D4C3E11302B07308C3D960D13840
>
> I am obviously looping through the length of the cookies array, retrieving
> the value, but also this unwanted text. What can I do to retrieve just the
> value please? It looks like my if condition is being satisified twice?!
>
> Frustrated
>
> Paul.
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>