JSP Tag Libraries

Скачать в pdf «JSP Tag Libraries»

3    The Tag Library Descriptor (TLD), which maps tag names to handler classes and provides tag-based syntactic information

JavaServer Pages API


Java Servlet API


‘Custom tag API


Figure 4.1 The Servlet, JSP, and Custom tag APIs

4 An extension to the web application deployment descriptor making it possible to point to the tag libraries used within the web application

In this chapter we’ll discuss the custom tag API and life cycle (elements 1 and 2). Elements 3 and 4, the TLD and web deployment descriptor, are covered in chapter

4.2 Overview of the tag API

The first stop on our walking tour is the custom tag API. The API is actually a small collection of Java classes and interfaces that allows developers to build their own custom tag libraries. The key definitions made by the API include:

1    How a tag should look to the JSP environment.

In other words, the methods a tag exposes to the JSP runtime.

2    What the JSP environment looks like to a tag.

In other words, the methods and objects the JSP runtime makes available to tags.

Judging from its role, you might expect the custom tag API to be huge, but it is not. The number of classes and interfaces directly related to custom tags is surprisingly small. In JSP1.1 there are only two interfaces and nine classes in the Java package containing the custom tag API (javax.servlet.jsp.tagext). These classes and interfaces are listed in tables 4.1 and 4.2. We can accomplish so much with so few classes because many of the classes and interfaces we use during our development actually belong to the much broader JavaServer Pages API, which is itself a part of the broader-yet Java Servlet API (see figure 4.1). Tasks commonly performed by tags, such as reading HTTP parameters, modifying cookies, using the Session, and writing content to a response are actually supported by classes and interfaces in these higher level APIs.

Скачать в pdf «JSP Tag Libraries»