Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem in cookie

 
sevi satalkar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there ,

i am facing problem with cookies ,i have also made session in the coding-
* it is storing a JSESSIONID & its corresponding value,eventhough i am not setting in it.
* also , plz. tell me the way if we can destroy the cookie that is
already present ,created by another user , before surfing the site .
Thanx !!!
-- sevika satalkar
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSESSIONID is the name of the cookie for the session. If you created a session for the client, it's going to have a cookie like this (or a rewritten address, e.g. http://www.microsoft.com/;JSESSIONID=23593 -- something like that anyways).
As for deleting the cookie, you're going about it the wrong way. In fact, you shouldn't be depending on the use of cookies when you utilize sessions in your web application. Remember, the URLs may have to be rewritten instead of using cookies all the time (in case the client has disabled them).
Short answer though: use HttpSession.invalidate(). This will kill the session, and any sort of cookies associated with it. If you're thinking about trying to delete the cookie manually, don't! You'll probably experience a bit of heartache doing it that way. Use the API for these things--that's what it's there for!
 
sevi satalkar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,
thanks for giving such a quick response .
in servlet api i have read this --

setMaxAge(int ) :-
A positive value indicates that the cookie will expire after that many seconds have passed. Note that the value is the maximum age when the cookie will expire, not the cookie's current age.
A negative value means that the cookie is not stored persistently and will be deleted when the Web browser exits. A zero value causes the cookie to be deleted.
when should be it set to zero , just before any one starts surfing the
site , will it do .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic