Can You Read Session Data in JavaScript?
When I looked this up, the internet responded with a resounding “NO!”
On StackOverflow, I found this:
(With Javascript, I assume that you mean client script in the browser.)
No, that is not possible. The contents of the Session object never leaves the server, so client script can’t read Session data directly.
If you want to access it in the browser, you have to read the data out of the Session object and send it along in the response (for example in a hidden field), or provide a web service that reads data from the Session object and returns to the browser.
So I did just that. If anyone needs one and works with Java Servlets, let me save you the trouble.
Posted in No Category by Eran with comments disabled.