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 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.