aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Tag Files - session implicit object availability Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Tag Files - session implicit object availability" Watch "Tag Files - session implicit object availability" New topic
Author

Tag Files - session implicit object availability

Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Howdy Ranchers!

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:

test.jsp


/WEB-INF/tags/testTag.tag


The result is:
JSP!
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?


OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1678
    
  25

Hi Pedro!

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!

Regards,
Frits
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Thanks Frits!

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?
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1678
    
  25

What do you think about that?

I think is is just wrong.

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


Regards,
Frits
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

Thanks Frits!

I'm glad we cleared this out :-)

Cheers!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tag Files - session implicit object availability