I'm reading SCWCD Study Companion by Charles Lyons and bumped into this statement:
SCWCD Study Companion (pp. 447) wrote:Note that all these implicit objects refer to the same objects as those in the calling JSP, with the exception of jspContext which is the JSP Context Wrapper, and session which is independent of the setting of the session attribute of the calling page's page directive (i.e. the tag file session object exists regardless of whether this implicit object exists in the calling page).
If I understand it correctly, even if I explicitly set session="false" in invoking JSP page, than the tag file should have the implicit object session available, right? It sounds impossible, so here is the test on Apache Tomcat 6.0.29:
The result is:
null END JSP!
If the session attribute of page directive in test.jsp file is changed to "true" than the Tag File returns HttpSession object correctly...
Did I understand something wrong?
EDIT: Ok, I think I get it :-)
If I would try to do in a JSP page where session attribute for page directive is set to false, than I'll get a compiler error. In these circumstances, the implicit object session will be always present in the Tag file, but will be always null, right?
and session which is independent of the setting of the session attribute of the calling page's page directive (i.e. the tag file session object exists regardless of whether this implicit object exists in the calling page).
This is not correct. The session object is dependent on setting of the surrounding page.
The page directive is defined for the whole page, that means that all tag-file's or custom tags that are used in the page cannot acces the Session object.
You can easily proof that it is wrong by creating a Servlet that sets an attribute in the Session (so it created a session) and then forwards to a jsp. In the jsp you use the page directive session="false" and you access a tag which is defined in a tag file. In the tag file you could now (according to Charles Lyon's book) get to the Session object that was created in the Servlet: but you can't!
That's what I suspected, but take a look at a exam question in the very same book:
SCWCD Study Companion, pp. 463, Ch16 Question 7 wrote:What is the effect of using the session JSP implicit object in a tag file when the invoking page sets the session="false" attribute of its page directive?
A. The tag file's session implicit object is never declared by the container.
B. The tag file's session implicit object is always null.
C. The tag file's session implicit object is initialised to the value of the client's current session.
D. A translation error occurs.
E. A compilation error occurs.
The correct answer is: C.
It makes no difference to the tag file whether the implicit object is initialised or not in the calling page - the tag file uses its JSP Context Wrapper to obtain the session object, regardless of the calling page.
What do you think about that?
Creator of Enthuware JWS+ V6
I have no specific part of the specs proving it is wrong but the following parts provide strong arguments:
JSP.1-8 Page Directive Attributes session Indicates that the page requires participation in an (HTTP)
If true then the implicit script language variable named session of type javax.servlet.http.HttpSession references the current/new session for the page. If false then the page does not participate in a session; the session implicit variable is unavailable, and any reference to it within the body of the JSP page is illegal
JSP.8.3 Semantics of Tag Files For each invocation to the tag, the JSP Context Wrapper must present a clean page scope containing no initial elements. All scopes other than the page scope must be identical to those in the Invoking JSP Context and must be modified accordingly when updates are made to those scopes in the JSP Context Wrapper.