• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tag Files - session implicit object availability

 
Ranch Hand
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 623
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Frits!

I'm glad we cleared this out :-)

Cheers!
 
Remember to always leap before you look. But always take the time to smell the tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic