Chapter 10. Custom Tag Development: When even JSTL is not enough...

image with no caption

Sometimes JSTL and standard actions aren’t enough.

When you need something custom, and you don’t want to go back to scripting, you can write your own tag handlers. That way, your page designers can use your tag in their pages, while all the hard work is done behind the scenes in your tag handler class. But there are three different ways to build your own tag handlers, so there’s a lot to learn. Of the three, two were introduced with JSP 2.0 to make your life easier (Simple Tags and Tag Files). But you still have to learn about Classic tags for that ridiculously rare occasion when neither of the other two will do what you want. Custom tag development gives you virtually unlimited power, if you can learn to wield it...

OBJECTIVES

Building a Custom Tag Library

10.1

Describe the semantics of the “Classic” custom tag event model when each event method (doStartTag(), doAfterBody(), and doEndTag()) is executed, and explain what the return value for each event method means; and write a tag handler class.

10.2

Using the PageContext API, write tag handler code to access the JSP implicit variables and access web application attributes.

10.3

Given a scenario, write tag handler code to access the parent tag and an arbitrary tag ancestor.

10.4

Describe the semantics of the “Simple” custom tag event model when the event method (doTag()) is ...

Get Head First Servlets and JSP, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.