Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cookies doubt

 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In our servlet code..we say request.getKookies() which returns cookies array.

My doubt is suppose i have a tomcat server in machine A

and the client accesses the site from machine B which already has cookies set from many sites...

Now when the user accesses the site and the code above gets executed,
will the cookie array contain all the cookies residing in the clients browser??

Regards
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, the browser will only serve cookies to the server from which they came.
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So is it the browsers responsiblity to send the cookie assosciated with the domain iam accessing with the request...
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ben!!


Suppose I have a web application(say site A) such that it should check from request of the client whether a cookie of site B exists and if exists show sometthing ..and if doesnt exists the show soemthing else....

How can we read the cookie of site B when the client requests on the site A.

Regards
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by A Kumar:
Thanks Ben!!


Suppose I have a web application(say site A) such that it should check from request of the client whether a cookie of site B exists and if exists show sometthing ..and if doesnt exists the show soemthing else....

How can we read the cookie of site B when the client requests on the site A.

Regards


I think, it is not possible as it's a matter of security.
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But if we want to access the cookie how to do about it..??
 
H Ritwick
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Web site can retrieve only the information that it has placed on your machine. It cannot retrieve information from other cookie files, nor any other information from your machine.

more info on http://computer.howstuffworks.com/cookie1.htm

hope this helps
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

From what i have read is that the a site can read only the cookie set by the same domain,
then why is that the request.getKookies() returns an array of cookies..

and the user has to iterate to get the required cookie...

Can't it directly give you the cookie...assosciated with the doamin..

or am i missing something ???

Regards
[ November 16, 2006: Message edited by: A Kumar ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can set mulitple cookies from an application.

You can not, however, read cookies set by other applications.
Think of the security problems that would exist if you could.
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For particular domain, you can store more than a Cookie. This is the reason why? API has a return type as Cookie[] array.

HTH,
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So a domain can set multiple cookies.. but whats the purpose for such a technique....to be used...


Just read that a browser is expected to support 20 cookies for each webserver,300 cookies in total and may limit cookie size to 4 Kb each.
[ November 16, 2006: Message edited by: A Kumar ]
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sometime your application might have the need to store multiple key value pairs of information.so multiple cookies from the same site is supported.
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I just found this URL...
Cross Domain Cookie Provider

Any suggestions!!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic