aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes PageContext in a Tag File 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 "PageContext in a Tag File" Watch "PageContext in a Tag File" New topic
Author

PageContext in a Tag File

Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 274

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.


SCJP 6 || SCWCD 5
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1717
    
  25

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

Joined: Jun 17, 2009
Posts: 274

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
Bartender

Joined: Apr 07, 2010
Posts: 1717
    
  25

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
 
 
subject: PageContext in a Tag File