Tags with Attributes

Attributes are used to pass information into a custom tag to configure the behavior of the tag. Tag attributes are like XML or HTML attributes and are name/value pairs of data. The values must be quoted with single or double quotes.

A simple example might be a tag that lists the rows in a table given a JNDI DataSource and table name as attributes. Listing 14.6 shows how such a tag could be used.

Listing 14.6. Full Text of lookup.jsp
 <%@ taglib prefix="demo" uri="/demo.tld" %> <HTML> <HEAD><TITLE>Tag Library Lookup Demo</TITLE></HEAD> <BODY> <demo:lookup dataSource="java:comp/env/jdbc/Agency" table="${param.table}"/> <H2>Select a table to display:</H2> <FORM action='lookup' > <SELECT name="table"> <OPTION>Applicant</OPTION> ...

Get Sams Teach Yourself J2EE™ in 21 Days, Second Edition now with O’Reilly online learning.

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