You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Abdul Wahab <aw...@erp21.com.my> on 2003/12/08 12:24:48 UTC

Cookies.

Hi All,

Im working with Tomcat5.0. I have problem in working with cookies. My
requirement is to save the user login info in browser cookie so that for
next time login will make easier for user to avoid entering again, like
usual login in other system.

So, I have added the cookies value in servlet, and I can get the cookie
value in jsp. When I work with the same browser fine working. But when close
and open the new browser window I cant get the cookie values.

Setting cookie,
	res.addCookie(new Cookie("entID",eID));
	res.addCookie(new Cookie("lgnId",lgnId));

After setting dispatching request and respond to the JSP page.
	Cookie[] cookies=request.getCookies();
	for (int i=0; i<cookies.length; i++) {
		hm.put(cookies[i].getName(), cookies[i].getValue());
	}
-- this is how i get the value in same browser.
When browse this jsp in new browser getting fail to retrieve..

Can you help me to solve this issue.

Thanks.

Wahab.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


[OT] Rad Game Tools

Posted by Graham Reeds <gr...@omnieng.co.uk>.
Does anyone else get a message from bink@radgametools.com asking them to
update their email address?

Everytime I email this list I get one back.

G.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Cookies.

Posted by Graham Reeds <gr...@omnieng.co.uk>.
> I checked the javadoc documentation for the Cookie class, and it doesn't
> seem to mention the default "life" of a Cookie object once sent to the
> browser. I'm inclined to think that the default is that it will live as
> long as the browser session does (especially because of your evidence).

It is.  I've been implementing cookies in my app.

> Try this:
>
> Cookie cookie = new Cookie("entId", eID);
> cookie.setMaxAge(cookie_life_in_seconds);
>
> res.addCookie(cookie);
>
> cookie = new Cookie("ognId", ignId);
> cookies.setMaxAge(cookie_life_in_seconds);
>
> res.addCookie(cookie);
>
> This is likely to extend the life of your cookies beyond the browser's
> session. Therefore, they will be sent in requests after the browser is
> restarted.

[OT]  Personally I think that being able to have a single name=value
attribute in a cookie is a bad idea.  I can't find anywhere that explains
the reason for this.  Anyway to get around this I have been looking at
formatting my cookie as:

name=lang:en;usr:grahamr;pswrd:fud;

and deencode the result afterwards.  Then you don't have to mess around with
lots of cookies.

G.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Re: Cookies.

Posted by Christopher Schultz <ch...@comcast.net>.
Abdul,

> So, I have added the cookies value in servlet, and I can get the cookie
> value in jsp. When I work with the same browser fine working. But when close
> and open the new browser window I cant get the cookie values.
> 
> Setting cookie,
> 	res.addCookie(new Cookie("entID",eID));
> 	res.addCookie(new Cookie("lgnId",lgnId));

I checked the javadoc documentation for the Cookie class, and it doesn't 
seem to mention the default "life" of a Cookie object once sent to the 
browser. I'm inclined to think that the default is that it will live as 
long as the browser session does (especially because of your evidence).

Try this:

Cookie cookie = new Cookie("entId", eID);
cookie.setMaxAge(cookie_life_in_seconds);

res.addCookie(cookie);

cookie = new Cookie("ognId", ignId);
cookies.setMaxAge(cookie_life_in_seconds);

res.addCookie(cookie);

This is likely to extend the life of your cookies beyond the browser's 
session. Therefore, they will be sent in requests after the browser is 
restarted.

-chris


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org