Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is relation between server side cookie and javascript cookie?

I want to know relation between cookies created by Cookie Class in Servlet and document.cookie in JS.

like image 716
John Martin Avatar asked May 09 '15 16:05

John Martin


1 Answers

document.cookie is a very odd property:

  • If you read its value, it gives you all of the cookies that the browser has stored that relate to the document, as one massive string. It's not...all that useful a format. It only gives you the cookie name and value, not any further information about the cookie like the path it relates to or when it expires. It's basically a semicolon list of name=value entries.

  • If you write its value, it adds or updates a cookie for the document in the browser. Subsequent requests to the server will carry this additional/updated cookie.

So the relationship is that it provides access, at the JavaScript level to the cookie data relevant to that document, which may have come from the server or may have been added by JavaScript.

like image 79
T.J. Crowder Avatar answered Sep 18 '22 08:09

T.J. Crowder