This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Cookie Path does not set properly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Cookie Path does not set properly" Watch "Cookie Path does not set properly" New topic

Cookie Path does not set properly

J.C. Bustamante

Joined: Jul 20, 2009
Posts: 22

I am running 2 different applications on the same server domain, but they are both using the same js function to create the cookie. If I set the cookie through javascript in application 1 as mentioned in the code below, the cookie will have the following information.

Name: a_Cookie
Value: 1
Host: localhost
Path: /

When I try to set the same cookie in application 2, a new cookie is created with the following information.

Name: a_Cookie
Value: 2
Host: localhost
Path: /app2

How do I get it so that both applications update the same cookie and not create separate cookies? Is there a way?

Please see the JS code below

JS function

App1 JS call

App2 JS call

Any help is very much appreciated!


Ankit Garg

Joined: Aug 03, 2008
Posts: 9399

You can use the window.location to find which app is running in your JS and then create the cookie accordingly (since the two applications are running on the same server so they must have a different context path which you can use for your advantage)...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Cookie Path does not set properly
It's not a secret anymore!