Can JavaScript read HTTP Session object?

fmjaguar3 picture fmjaguar3 · Mar 19, 2012 · Viewed 23.8k times · Source

Is it possible to read the value of a dynamic variable like httpRequest.getSession("attr_name") from within a JavaScript?

Answer

Guffa picture Guffa · Mar 19, 2012

(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.