We help IT Professionals succeed at work.

Accessing a session variable in javascript

wired_up asked
Last Modified: 2008-03-10
I am using java servlets to create the main body of a html page, in this session variables are set for login information:

HttpSession session = request.getSession(true);
session.putValue("userCode", lsUserCode);
session.putValue("password", password);


Then later on one of the i want to check if the user's session is still active, i want to do with within the javascript, can i do this?
 -i have been doing :

var userCode = session("userCode");

but the javascript dosn't seen to reconise the session variable, i get the error message - "object expected".

Any help would be appreciated.

Watch Question

in your javascript try this:

var userCode = <%=session("userCode")%>
This one is on us!
(Get your first solution completely free - no credit card required)
Also the page  you want to create must be a jsp page, not an html
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.