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

Cookie and HttpSession object, which one to use when?

 
Sujatha Kalluri
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This is the interview question asked to me, can anybody explain me in which situations we prefer to use Cookie and in which we prefer Session object for session management.
thanks,
Sujatha.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is kind of strange question, cause the Cookie exists on client side
and identifies to which session the request belongs. And the session object keeps informations about the session.
So both cooperate and are no alternatives
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would want to point out that Cookies have a controllable life-time so you can keep information between user sessions if you want. Also you have fine control over where cookies are valid (whole site vrs one application)
Do a search for rfc2109 to find out more about the cookie specs.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic