You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Vaduvoiu Tiberiu <va...@yahoo.com> on 2007/07/30 09:28:42 UTC
tomcat and cookies problem
Hi, guys. I'm running tomcat 6.0.3 and I'm having a problem with cookies in jsp. After I set a cookie time using cookie.setMaxAge(3600), when I run cookie.getMaxAge() I get -1 instead of 3600(cookie is a object of type javax.servlet.http.Cookie). As I read on the internet about this issue I understood that depending on application server and configuration, cookies can be generated automatically by servlet engine. In such case you can control the max age trough configuration. As I understand, the reason why i get -1 is because
The server sets cookie values using this response header:
Set-Cookie: NAME=VALUE; expires=DATE;
path=PATH; domain=DOMAIN_NAME; secure
while client sends cookies using this request header:
Cookie: NAME1=OPAQUE_STRING1; NAME2=OPAQUE_STRING2
So to my understanding, I need to configure this somehow in tomcat. true? I haven't found any articles related to this though anywhere. Can someone help me out with some info?? 10x a lot in advance
____________________________________________________________________________________Ready for the edge of your seat?
Check out tonight's top picks on Yahoo! TV.
http://tv.yahoo.com/
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: tomcat and cookies problem
Posted by Bill Barker <wb...@wilshire.com>.
>"Vaduvoiu Tiberiu" <va...@yahoo.com> wrote in message
> >news:169411.44964.qm@web51301.mail.re2.yahoo.com...
>Hi, guys. I'm running tomcat 6.0.3 and I'm having a problem with cookies in
>jsp. After I set a cookie time using >cookie.setMaxAge(3600), when I run
>cookie.getMaxAge() I get -1 instead of 3600(cookie is a object of type
> >javax.servlet.http.Cookie). As I read on the internet about this issue I
>understood that depending on application server >and configuration, cookies
>can be generated automatically by servlet engine. In such case you can
>control the max age trough configuration. As I understand, the reason why i
>get -1 is because
>
>The server sets cookie values using this response header:
>Set-Cookie: NAME=VALUE; expires=DATE;
>path=PATH; domain=DOMAIN_NAME; secure
>
>while client sends cookies using this request header:
>Cookie: NAME1=OPAQUE_STRING1; NAME2=OPAQUE_STRING2
>
>So to my understanding, I need to configure this somehow in tomcat. true? I
>haven't found any articles related to this >though anywhere. Can someone
>help me out with some info?? 10x a lot in advance
>
>
So, close :). The problem, as you have stated, is that the browser can't
send the 'expires' back to Tomcat according to the RFC, so Tomcat has
absolutely no idea what it is when it gets the cookie back from the browser.
Tomcat just sends the cookie back to the browser, and doesn't keep track of
it otherwise.
Work-arounds include adding the date value to the cookie somehow, or when
you create the cookie do something like:
<% session.setAttribute("myCookieSetDate", new Date()); %>
---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org