tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: cookie retrieval
Date Fri, 08 Mar 2002 04:45:29 GMT


On Fri, 8 Mar 2002, Paul Wallace wrote:

> Date: Fri, 8 Mar 2002 10:51:31 +0700
> From: Paul Wallace <paul.wallace@mustang-technologies.com>
> Reply-To: Tomcat Developers List <tomcat-dev@jakarta.apache.org>,
>      Paul Wallace <paul.wallace@mustang-technologies.com>
> To: Tomcat Developers List <tomcat-dev@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:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message