It will under the hoods use JspContext#findAttribute()
to find the attribute. The linked javadoc mentions the following:
Searches for the named attribute in page, request, session (if valid), and application scope(s) in order and returns the value associated or null.
So, it will return the first non-null value which is found after searching in the order of page, request, session and application (servletcontext) scopes.
If you have attributes with the same name in multiple scopes and/or you'd like to get the attribute from a specific scope, then you can access it by the attribute maps available by the ${pageScope}
, ${requestScope}
, ${sessionScope}
and/or ${applicationScope}
. E.g.
${requestScope.track}
Back to your actual problem: if you have problems with accessing session scoped attributes, then it can only mean that the JSP is not using the same session as the servlet is using. You can debug it by printing the Session ID in servlet as follows
System.out.println(session.getId());
and in JSP by
${pageContext.session.id}
Both should print the same. If not, then it is definitely not sharing the same session. The session is domain, context and cookie dependent.
You can display all available session attributes by just printing ${sessionScope}
. It will display a string in format as described in AbstractMap#toString()
, containing all session attributes.
${sessionScope}