• 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

PageContext in a Tag File

 
Ranch Hand
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm reading Head First Servlets and JSP (2nd edition) and found what looks like a typo, but I want to make sure I'm not missing anything. I couldn't find any corrections in the errata.

On p.510 in the answer to the first question, it says that the request and response implicit objects are available in a Tag File just like in a JSP (yup that makes sense), but that,

You don't have a ServletContext, though--a Tag File uses a JspContext instead of a ServletContext.


I think this should read,

"You don't have a PageContext, though--a Tag File uses a JspContext instead of a PageContext"

Testing this out, when I try accessing the application implicit object in a Tag File, everything works fine.


But when I try accessing an implicit object called pageContext, it gives me an error. However, accessing an implicit object called jspContext works OK. Thanks.
 
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
Michael,

Tag files are suppose to be scriptlet free!

The JSP container generates a SimpleTagSupport class from the Tag file. Furthermore for SimpleTags you can't choose a bodyContent of JSP (only scriptless, empty or tagdependent are allowed)

The way to access the application object is by using EL:

Regards,
Frits
 
Michael Angstadt
Ranch Hand
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Frits Walraven wrote:Tag files are suppose to be scriptlet free!



Gawd, yes, yes, I know! I'm not a n00b, geez. But it's still possible to put scriptlets in a Tag File (but never in the bodies of custom tags).
 
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
Michael,

Just like Bear says in this Thread

Just because you can, doesn't mean that you should. If you are using tag files, that means JSP 2.0. And scriptlets have no business anywhere in a JSP 2.0 application.


Regards,
Frits
 
They worship nothing. They say it's because nothing is worth fighting for. Like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic