0

I am trying to get the path of a cookie

I have several cookies with the same name but with different paths.

The following example return null using the getpath() method

var request = facesContext.getExternalContext().getRequest(); 
var cookies = request.getCookies();
print(cookies[1].getName()))
print(cookies[1].getPath()))

I also tried the global object "cookie" in xpages but how do I get the path from that?

How can I get the path of all the cookies using ssjs?

enter image description here

Thomas Adrian
  • 3,543
  • 6
  • 32
  • 62

2 Answers2

2

You can't. Googled a bit. Seems to be a common problem beyond Domino and XPages. Both getDomain and getPath return null, because browser does not send it to the server. Explained here getDomain() of javax.servlet.http.Cookie is returning null

Also a short thought here https://coderanch.com/t/283519/java/Cookie-getDomain-returns-null that it may be security feature.

Community
  • 1
  • 1
Frantisek Kossuth
  • 3,524
  • 2
  • 23
  • 42
1

Both ways of getting a cookie return a java.servlet.http.Cookie, which does have the getPath() method, which you're using. Are you sure the path is getting set? Looking at an POST request from an XPage (both via the servlet it's calling and FireBug), the DomAuthSessId and SessionID cookies don't have a path set, so getPath() returns null.

Paul Stephen Withers
  • 15,699
  • 1
  • 15
  • 33