John,

I had a similar problem, which seem to be resovled by explicitly setting 
the path of the cookie to "/" before adding it to the response.

    Cookie userCookie = new Cookie("U_ID", userId);
    userCookie.setMaxAge(946080000);
    userCookie.setPath("/");
    httpResp.addCookie(userCookie);

After reading the Servlet docs, it seems the behaviour for setting a 
cookie without first setting it's path is undefinded. I've found that 
with Tomcat, new Cookies use the current URL of the request instead of 
the "/" when a path is not specified. I also believe there may have been 
a few bugs with previous versions of Tomcat and Cookies which have been 
resolved with newer versions.

Hope this helps,

~Scott
              

John Regan wrote:

>I am John Regan.
>
>Environment:
>NT
>IE 5.0
>Tomcat 4.0
>Struts 1.0
>
>When a user requests our index page we write a pagehit sequence # to the
>client's cookie through the following code:
>       //no cookie exits
>               else {
>                Cookie pcookie = new Cookie("P",r.getPagehitcode());
>                pcookie.setMaxAge(60*60*24*365);//1 year
>                response.addCookie(pcookie);                  
>               } 
>which works fine, I look in my cookies directory and find a file named
>jbr@jsp[1].txt(where does it grab this name from?) which contains the
>correct value for "P".
>The user clicks on a link on the homepage, this where things start to go
>very wrong.  In the action class I loop through cookie values in the
>following manner:
>
>                Cookie[] cookies = request.getCookies();
>                Cookie cookie;
>               Cookie schangecookie = null;
>               if (cookies != null) {
>                    for(int i=0; i<cookies.length; i++) {
>                        cookie = cookies[i];
>                        servlet.log("cookie" + cookie.getName() + " " +
>cookie.getValue());
>                        if (cookie.getName().equals("P")) {
>                            schangecookie = (Cookie)cookie.clone();
>                            schangecookie.setValue(r.getPagehitcode());
>                            response.addCookie(schangecookie);
>                     }
>                }
>
>The log shows the only cookie in the request is the following:
>
>JSESSIONID A37259C0F90335C6B3B177A1C2679413
>
>The "P" value which I see in my cookie is not in the request!  Not to
>mention, I don't where JSESSIONID is stored!
>
>Can someone clue me in to what might be happening?
>
>Any help is much appreciated!
>




--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to