Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Cookies  RSS feed

 
Kiran Kb
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi all,

What is the point in having getCookies() in javax.servlet.http.Cookie.
I think at any point of time, there will be only one Session associated with a Client.
So there will be one Cookie associated with that particular Session.
That cookie will have a single key-value pair. The key identifies the client.
So why we have to getCookies(), iterate the array to find our wanted key?
Why would we have multiple key-value pairs for a client. Can any one give an
example for the same?

Kiran

 
Devaka Cooray
Marshal
Posts: 5323
575
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you said, there are one only one session for a client, but it doesn't mean that there are only one cookie for a client. The session information (i.e. session id) is stored in the client by using a separate cookie, which has the key named "JSESSIONID" and the value is the session id. In addition to that, there can be many other cookies for storing external data on the client.
 
Kiran Kb
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

For example as you said, cookie is a piece of info to identify the client right?
So say username is the information added to the response by the server.
So,
the response header will have

Set-cookie:username=smith

The next request from client will have its header as

Cookie:username=smith

The Server looks for username smith and associates the cliete to that HttpSession.
Thats it. What else can be stored on the client?? Why getCookies? Why not getCookie()?

And how can HttpSession and Cookies be related programatically.

And how to store cookies on the client(browser) even after the browser shuts down.??
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Identifying users is only one use of cookies. The easiest way to find out how sites make use of more than a one cookie is to look at what they store in them. In Firefox: Preferences/Options -> Privacy -> Show Cookies... Voila!

 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

And how can HttpSession and Cookies be related programatically.

And how to store cookies on the client(browser) even after the browser shuts down.??


How the cookie is actually used depends on the website in question. They may contain additional information like your preferences or can be used to log you in automatically for X weeks etc etc. A cookie's age determines how long it lives on your comp.

Client identification cookies goes by the name JSESSIONID. Other cookies are application specific. Browsers persist the cookies on a persistence store. Thats a fancy way of saying they save the cookies somewhere on the hard disk
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!