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?

Get Head First Servlets and JSP, 2nd 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.