This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Cookie and HttpSession object, which one to use when? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Cookie and HttpSession object, which one to use when?" Watch "Cookie and HttpSession object, which one to use when?" New topic
Author

Cookie and HttpSession object, which one to use when?

Sujatha Kalluri
Ranch Hand

Joined: Oct 09, 2002
Posts: 33
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

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Mar 22, 2000
Posts: 12761
    
    5
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
 
wood burning stoves
 
subject: Cookie and HttpSession object, which one to use when?
 
Similar Threads
Alternative to Cookie?
please tell me when to use Session and Cookie?
Session vs Cookie objects
Use of Cookie
Browser close > session cookie vanishes ??