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/08 04:51:31 UTC
cookie retrieval
Hi, a have a JSP page to setup a cookie (Tomcat server):
cook = new Cookie("memberCookie", userid);
cook.setPath("c:/Program Files/jakarta-tomcat-4.0/webapps/mydir/login/");
response.addCookie(cook);
response.sendRedirect("http://myhost/somelocation/mydir/bookings/enterDate.j
sp");
and the page to retrieve the cookie (enterDate.jsp) is:
Cookie cookies[] = request.getCookies();
if(cookies != null) {
for(int i = 0; i < cookies.length; i++) {
if (cookies[i].getName().equals("memberCookie"));
out.println("Welcome: " + cookies[i].getValue());
}
}
Here's the conundrum, if the cookie is retrieved from a page that is in a
DIFFERENT directory that setup the cookie , the output (getValue) returns
only a sessionID ie "8455352001D0C01849A2C480576723D8" and not the required
value. BUT, if the cookie is retrieved from a file in the SAME directory of
setup, the desired output is obtained, plus the same JSESSIONID info. How
may I simply obtain the value of the cookie from any directory, and not the
session ID? I have tried using setPath (above) pointing to the setup and
destination directories with same unwanted session ID output.
Perhaps my syntax of setPath is the problem here? Surely I do not have
to setup and retrieve cookies using files that are in the same directory?
Thanks for all input
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>
cookie retrieval II
Posted by Paul Wallace <pa...@mustang-technologies.com>.
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
Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Fri, 8 Mar 2002, Paul Wallace wrote:
> Date: Fri, 8 Mar 2002 10:51:31 +0700
> From: Paul Wallace <pa...@mustang-technologies.com>
> Reply-To: Tomcat Developers List <to...@jakarta.apache.org>,
> Paul Wallace <pa...@mustang-technologies.com>
> To: Tomcat Developers List <to...@jakarta.apache.org>
> Subject: cookie retrieval
>
> Hi, a have a JSP page to setup a cookie (Tomcat server):
>
> cook = new Cookie("memberCookie", userid);
> cook.setPath("c:/Program Files/jakarta-tomcat-4.0/webapps/mydir/login/");
This is not a disk "path" -- it is the server-relative part of a request
URL. For example, if your webapp is installed at context path "/myapp",
and you want cookies generated by this webapp to *only* be returned to the
same webapp, you would say cook.setPath("/myapp") as well. (This is what
Tomcat does to make sure that session id cookies only go back to the
application that sent them.
See the Cookie Specification for more info:
<http://www.ietf.org/rfc/rfc2109.txt>.
> response.addCookie(cook);
> response.sendRedirect("http://myhost/somelocation/mydir/bookings/enterDate.j
> sp");
>
> and the page to retrieve the cookie (enterDate.jsp) is:
>
> Cookie cookies[] = request.getCookies();
> if(cookies != null) {
> for(int i = 0; i < cookies.length; i++) {
> if (cookies[i].getName().equals("memberCookie"));
> out.println("Welcome: " + cookies[i].getValue());
> }
> }
>
> Here's the conundrum, if the cookie is retrieved from a page that is in a
> DIFFERENT directory that setup the cookie , the output (getValue) returns
> only a sessionID ie "8455352001D0C01849A2C480576723D8" and not the required
> value. BUT, if the cookie is retrieved from a file in the SAME directory of
> setup, the desired output is obtained, plus the same JSESSIONID info. How
> may I simply obtain the value of the cookie from any directory, and not the
> session ID? I have tried using setPath (above) pointing to the setup and
> destination directories with same unwanted session ID output.
> Perhaps my syntax of setPath is the problem here? Surely I do not have
> to setup and retrieve cookies using files that are in the same directory?
>
> Thanks for all input
>
> Paul.
>
Craig
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>