Java Reference
In-Depth Information
L ISTING 19.5
HelloBody.jsp
<%@ taglib uri=”/djs” prefix=”djs” %>
<html>
<body>
<djs:helloBody>Bob</djs:helloBody>
</body>
</html>
Now open your browser to the following URL:
http://localhost/djs/HelloBody.jsp
You should see an image similar to Figure 19.3.
F IGURE 19.3
The HelloBody Tag Page.
Tags with Attributes
The last tag you will develop is a tag with attributes. With JSP custom tags you have the ability
to pass attributes to custom tags. You do this by adding an attribute list to the tag element. An
example of this, using a modification of the original hello tag, is in the following code snip-
pet:
<djs:helloAttribute name=”Bob”/>
The preceding snippet has only one attribute: name . When the JSP container encounters this tag
it then checks its matching tag handler for a class-level attribute name . It uses introspection to
find this attribute and then calls its set XXX () method. All tags must have a matching set
method for each attribute that can be included in the tag element's attribute list. The matching
method for the above snippet would be the setName() method. To further examine how this
works, let's develop a tag with attributes.
Search WWH ::




Custom Search