Chapter 13. Creating New Tag Libraries

Since Chapter 4, we have seen that custom tag libraries are an invaluable asset. The time has now come to learn how to create new ones. Fundamentally, tags are not much more complicated than servlets; in fact, servlets could be used to construct a very limited form of custom tag. If it rendered the current time to a page, a servlet could be used almost as a “tag”:

<jsp:include page="/dateServlet">
  <jsp:param name="format" value="HH:MM:SS"/>

Alternatively, if tags were implemented as servlets and held to the bean naming conventions, the page compiler could take a simple JSP:

Here is the date:
<awl:date format="HH:MM:SS"/>

and turn it into the following code:

 public void service(HttpServletRequest ...

Get JavaServer Pages™, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.