Chapter 7. Using Custom Tag Libraries and the JSP Standard Tag Library

So far we’ve covered the JSP basics -- the primary parts of a page and installation and execution of a page -- and how to use beans to dynamically add content to a page. Before we start working on real applications, let’s turn to another fundamental JSP feature: custom tag libraries.

Custom tag libraries are, in my opinion, what make JSP so powerful. They make it possible for page authors to embed pretty much any logic in a page using familiar, HTML-like elements. In this chapter, we take a close look at what a custom tag library is, how to install and use it, and what the JSP Standard Tag Library (JSTL) brings to the table.

What Is a Custom Tag Library?

The JSP standard actions, such as the <jsp:useBean> and <jsp:getProperty> actions used in Chapter 6, are HTML-like elements for commonly needed functions in a JSP page: creating beans, accessing bean properties, and invoking other JSP pages. But there’s a lot more you want to do that isn’t covered by the standard actions.

To extend the set of action elements a page author can use in the same familiar way, a Java programmer can develop new actions based on classes defined by JSP specification. Such actions are called custom actions. A custom action can do pretty much anything: it has access to all information about the request, it can add content to the response body as well as set response headers, and it can use any Java API to access external resources such ...

Get JavaServer Pages, Second 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.