O'Reilly logo

Head First Servlets and JSP, 2nd Edition by Bert Bates, Bryan Basham, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

When an attribute value is really big

Imagine you have a tag attribute that might be as long as, say, a paragraph. Sticking that in the opening tag could get ugly. So, you can choose to put content in the body of the tag, and then use that as a kind of attribute.

This time we’ll take the subTitle attribute out of the tag, and instead make it the body of the <myTags:Header> tag.

image with no caption

Note

We no longer need the attribute directive!

Inside the Tag File (Header.tag)

image with no caption

Inside the JSP that uses the tag

<%@ taglib prefix="myTags" tagdir="/WEB-INF/tags" %>
<html><body>

<myTags:Header>
   We take the sting out of SOAP. OK, so it's not Jini,<br>
   but we'll help you get through it with the least<br>
   frustration and hair loss.
</myTags:Header>

Note

Now we just give the tag a body, instead of putting all this as the value of an attribute in the opening tag.

<br>
Contact us at: ${initParam.mainEmail}
</body></html>

But we’re back to the same problem we had before—without a TLD, where do you declare the body-content type?

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required