aspose file tools*
The moose likes Servlets and the fly likes Cookies doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Cookies doubt" Watch "Cookies doubt" New topic
Author

Cookies doubt

A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 978
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

Joined: Dec 11, 2004
Posts: 13410

No, the browser will only serve cookies to the server from which they came.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 978
So is it the browsers responsiblity to send the cookie assosciated with the domain iam accessing with the request...
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Yes
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 978
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

Joined: Oct 11, 2004
Posts: 3830
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

Joined: Jul 04, 2004
Posts: 978
But if we want to access the cookie how to do about it..??
H Ritwick
Greenhorn

Joined: Mar 15, 2006
Posts: 18
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

Joined: Jul 04, 2004
Posts: 978
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

Joined: Dec 11, 2004
Posts: 13410

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

Joined: Nov 16, 2005
Posts: 502

For particular domain, you can store more than a Cookie. This is the reason why? API has a return type as Cookie[] array.

HTH,


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 978
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

Joined: Nov 29, 2005
Posts: 2308
Sometime your application might have the need to store multiple key value pairs of information.so multiple cookies from the same site is supported.


Rahul Bhattacharjee
LinkedIn - Blog
A Kumar
Ranch Hand

Joined: Jul 04, 2004
Posts: 978
Hi,

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

Any suggestions!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cookies doubt
 
Similar Threads
Doubt........
Session Doubt?
Doubt regarding the cookies.
Doubt in Listner
Doubt on cookies