RE: Off topic:cookies nightmare!!!!!!!!

2002-04-29 Thread John Regan

THAT WAS IT!!  Scott, thank you so much for the quick response, and thank
you Craig for the clarification!!  Happy Monday.

-Original Message-
From: Craig R. McClanahan [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 29, 2002 2:49 PM
To: Tomcat Users List
Cc: [EMAIL PROTECTED]; Struts Users (E-mail)
Subject: Re: Off topic:cookies nightmare




On Mon, 29 Apr 2002, pixel wrote:

> Date: Mon, 29 Apr 2002 17:42:13 -0400
> From: pixel <[EMAIL PROTECTED]>
> Reply-To: Tomcat Users List <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Cc: Tomcat Users List <[EMAIL PROTECTED]>,
>  "Struts Users (E-mail)" <[EMAIL PROTECTED]>
> Subject: Re: Off topic:cookies nightmare
>
> 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(94608);
> 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.
>

Setting the cookie path to "/" will cause this cookie to be sent back to
*all* web applications on your server, not just yours.  It is safer to set
the cookie path to return just to your web application:

  userCookie.setPath(request.getContextPath());

> Hope this helps,
>
> ~Scott

Craig



Re: Off topic:cookies nightmare!!!!!!!!

2002-04-29 Thread Craig R. McClanahan



On Mon, 29 Apr 2002, pixel wrote:

> Date: Mon, 29 Apr 2002 17:42:13 -0400
> From: pixel <[EMAIL PROTECTED]>
> Reply-To: Tomcat Users List <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Cc: Tomcat Users List <[EMAIL PROTECTED]>,
>  "Struts Users (E-mail)" <[EMAIL PROTECTED]>
> Subject: Re: Off topic:cookies nightmare
>
> 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(94608);
> 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.
>

Setting the cookie path to "/" will cause this cookie to be sent back to
*all* web applications on your server, not just yours.  It is safer to set
the cookie path to return just to your web application:

  userCookie.setPath(request.getContextPath());

> Hope this helps,
>
> ~Scott

Craig


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




Re: Off topic:cookies nightmare!!!!!!!!

2002-04-29 Thread pixel

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(94608);
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; icookie = 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:   
For additional commands: 
Troubles with the list: 




Off topic:cookies nightmare!!!!!!!!

2002-04-29 Thread John Regan

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