How much (application, servletContext, httpSession) will EL use to interpret attributes
when I use <c:out value="${track}"> in jsp, where should the track attribute be located (servletContext, httpSession and request)?
I tried setting the controller for the track attribute to httpSession, but then ${track} does not give me anything in .jsp. On the other hand, if I set it to servletContext, ${track} give me a value. This does not seem right. Can you indicate the direction in which attributes pass between .jsp (using jstl) and controllers (.java)? Thanks in advance.
To search for an attribute under the hoods, use JspContext#findAttribute() . The related javadoc mentions the following:
Searches for the named attribute on the page, request, session (if valid), and application scope in order and returns a value that is bound or null.
Thus, it will return the first non-zero value that will be found after searching in the order of pages, request, session and application (servletcontext).
If you have attributes with the same name in several areas and / or you want to get an attribute from a certain area, then you can access it using attribute maps available with ${pageScope} , ${requestScope} , ${sessionScope} and / or ${applicationScope} . For instance.
${requestScope.track} See also:
Let's get back to your real problem: if you have problems accessing attributes that are limited by the session, this may mean that the JSP is not using the same session as the servlet. You can debug it by printing the session id in servlets as follows
System.out.println(session.getId()); and in JSP -
${pageContext.session.id} Both should print the same thing. If not, then it will definitely not use the same session. The session depends on the domain, context and cookie.
You can display all available session attributes by simply printing ${sessionScope} . It will display a string in the format described in AbstractMap#toString() containing all session attributes.
${sessionScope}