This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JSP and the fly likes Unable to retrieve cookie either through JSP or Javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "Unable to retrieve cookie either through JSP or Javascript" Watch "Unable to retrieve cookie either through JSP or Javascript" New topic
Author

Unable to retrieve cookie either through JSP or Javascript

lavi mendonca
Ranch Hand

Joined: Apr 24, 2002
Posts: 53
Hi,

I have a requirement to delete a particular cookie on click of a hyperlink displayed on my site. On clicking this hyperlink on my website, a new window of another website pops up which creates and stores cookie on the client machine. But i am unable to retrieve the cookie (that was stored by the other website). I tried using document cookie call (with Javascript) as well as get cookies method of the request object (with JSP). If i check the list of cookies explicitly through the browser, i can see the same cookie with its value. But though my code, i am unable to retrieve it.

Can anybody shed some light on this and let me know how to read and then delete cookies (that are created by another website) through the Javascript code in my website.

Any help would be appreciated.

Thanks in advance !
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61306
    
  66

"perlavi",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61306
    
  66

Originally posted by perlavi:
But i am unable to retrieve the cookie (that was stored by the other website).
Cookies are only available to the domains that created them.

how to read and then delete cookies (that are created by another website) through the Javascript code in my website.
You can't.
lavi mendonca
Ranch Hand

Joined: Apr 24, 2002
Posts: 53
Thanks Bear Bibeault for your quick response. Just to confirm, I won't be able to even read the cookies that have been created by another website, right ??

Thanks again.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61306
    
  66

Right.
Prasad Tamirisa
Ranch Hand

Joined: Mar 26, 2007
Posts: 130
I won't be able to even read the cookies that have been created by another website, right ??


Absolutely. When you use request.getKookie method, it tries to look for the cookies that are corresponding to your server. You can't control the stuff created by an other server.

Imagine, If that can be done, ... It means that you can control every website in the web.
[ May 28, 2008: Message edited by: Prasad Tamirisa ]

Regards,
Durga Prasad
lavi mendonca
Ranch Hand

Joined: Apr 24, 2002
Posts: 53
Thank you to both Bear Bibeault and Prasad for your inputs.
 
GeeCON Prague 2014
 
subject: Unable to retrieve cookie either through JSP or Javascript