File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Sessions and cookies Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Sessions and cookies" Watch "Sessions and cookies" New topic

Sessions and cookies

Arvind Mahendra
Ranch Hand

Joined: Jul 14, 2007
Posts: 1162
The one concept that always eludes me. What is the link between sessions and cookies?
When I close my browser I lose my session id. But the session object sticks around. And when my session Id is gone so is my cookie? what happens to my cookie?

I want to be like marc
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
Unless it expired, nothing happened to your cookie. If your session is still good on the server and you go back, the cookie will be used to access that existing session. If the session has timed out on the server and you go back with that cookie, you will get a new session and a cookie with a new session id
praveen oruganti
Ranch Hand

Joined: Feb 05, 2007
Posts: 74
What is the diff b/w cookie ans session.

Regards,<br />Praveen Oruganti<br />Software Programmer
Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

Originally posted by praveen oruganti:
What is the diff b/w cookie ans session.

Rough Summary: A cookie is tiny text file stored in the client browser. A session is an object on the server that can store information. Either one can be utilized to track user activity, preferences and what not. Other than that, there is not much in common.

A good workman is known by his tools.
Marcus Green
arch rival

Joined: Sep 14, 1999
Posts: 2813
The default way of tracking sessions is via a cookie that contains a long number designed to be unique that maps to the session on the server. So when your browser makes a request, it sends the cookie to the server and the server looks up the session associated with that ID and thus it can run "the program" with variables in a state just for your current condition in running the web application.......

Cookies can be used to store other pieces of data. I have the misfortune of using cookies with Perl programming in the early days of the web and it is not something I would like to go back to.

SCWCD: Online Course, 50,000+ words and 200+ questions
praveen oruganti
Ranch Hand

Joined: Feb 05, 2007
Posts: 74
Thanks Marc Peabody and Marcus Green
I agree. Here's the link:
subject: Sessions and cookies
It's not a secret anymore!