jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes Difference between Cookies and Session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Difference between Cookies and Session" Watch "Difference between Cookies and Session" New topic

Difference between Cookies and Session

Mahendran Aiyappan
Ranch Hand

Joined: Sep 05, 2005
Posts: 102
Can anybody say the difference between Cookies and Session

Pavel Kubal
Ranch Hand

Joined: Mar 13, 2004
Posts: 360
Check this out, I hope this helps you.

Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

Cookies are placed on the client machine. Cookies contain String name/value pairs. They can be turned off by a client, or a client can reject them, so they are a somewhat unreliable way of placing information on a client machine.

A session, or HttpSession, is part of the Servlet API, and helps to turn a stateless protocol, like HTTP, into a stateful protocol.

Here's more information than you ever wanted to know about the HttpSession.


"The HttpSession adds state to a stateless, web based, interaction with a server. When a client makes a call to an application server, a Servlet developer can programmatically create and associate an HttpSession with that client. The session can then be used to keep track of all sorts of information about the user.

If the user tells us their favorite color, we can store that information in their session. If the user gives us their address and phone number, we can store that in their session. If they�re taking an online exam, we can put the answer to every question they�ve been given into the session as well. We can then go back into that session object, at any point in time, and pull that information out.

So when a user is done taking an online exam, we can go into their session and find out which questions they got correct, and which questions they got wrong. If the client is picking out books, or other products they want to purchase, when they click �check out,� we can go into their session, process their order, and tell them how much their purchase will be.

HttpSessions add state to a stateless protocol, and they are pivotal in making online applications work."

I agree. Here's the link: http://aspose.com/file-tools
subject: Difference between Cookies and Session
It's not a secret anymore!