File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes accessing cookies set by one app using another app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "accessing cookies set by one app using another app" Watch "accessing cookies set by one app using another app" New topic

accessing cookies set by one app using another app

alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
the problem is simple, i have 2 applications deployed on the same server (2 different context roots). i use javascript to set a client-side cookie in the first app. since the 2nd app sits on the same web and application server (the same domain), the second app should be able to read the cookie set by the first app correct? no luck. any help is appreciated.

js script in my
(please substitute cookie for 'kookie' since javaranch doesn't allow this specific js script comination)

2. returns nothing
and the js equivalent to read the cookie returns null (cookie does not exist). i have searched everywhere without much luck.
[ May 19, 2005: Message edited by: alan do ]

-/a<br />certified slacker...yes, my last name is 'do' - <a href="" target="_blank" rel="nofollow"></a>
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

Are you sure it's being set?
Can you read it from the first app?

Have you looked in your browser's cookie manager to see if it's there?

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

Joined: Apr 14, 2005
Posts: 354
yup, i am very sure. if i put the same test file as i have in app2 into app1 to check, it's there.
Neeraj Dheer
Ranch Hand

Joined: Mar 30, 2005
Posts: 225

Cookies can only be seen by the 'server' that sent them. This by default would be the context of your application, right?

can you do a kookie.setDomain("url_of_root_context")? cookies are available only to the context that set them and to all its sub-directories. so if your first app set the kookie, it would be avalable to it and all its sub-directories, but not the parent directory or any other directory.

If you do a kookie.setDomain("root_context") then the kookie will be available to all apps residing under that context.
alan do
Ranch Hand

Joined: Apr 14, 2005
Posts: 354
i really appreciate the reply. i am struggling with the 'domain' concept of cookies. when i specified the 'domain' when setting up the cookie, even app1 can't find it. the underlying issue may be that the 'domain' that i see isn't what its really is (as seen by the browser/cookie).

i've tried settting the cookie w/o specifying the domain and tried to read the domain information from the cookie. per the cookie specs, the 'default' domain is set if none is specified. still, i am unable to 'read' what this 'default' domain is using JSTL although i can see the value and object reference.

the domain complication MAY be due to the applications being under Tivoli Access Manager (which does redirect after authentication). if it's at all important, both applications are struts apps, running under WAS/WSAD Test Environment. thanks for any more thought anyone can give.
I agree. Here's the link:
subject: accessing cookies set by one app using another app
It's not a secret anymore!