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

Declaring body-content for a Tag File

The only way to declare body-content type for a Tag File is with another new Tag File directive, the tag directive. The tag directive is the Tag File equivalent of the page directive in a JSP page, and it has a lot of the same attributes plus an important one you won’t find in page directive—body-content.

For a custom tag, the <body-content> element inside the <tag> element of a TLD is mandatory! But a Tag File does not have to declare <body-content> if the default—scriptless—is acceptable. A value of scriptless means you can’t have scripting elements. And scripting elements, remember, are scriptlets (<% ... %>), scriptlet expressions (<%= ... %>), and declarations (<%! ... %>).

In fact, the bodies of Tag File tags are never allowed to have scripting, so it’s not an option. But you can declare body-content (using the tag directive with a body-content attribute) if you want one of the other two options, empty or tagdependent.

You CANNOT use scripting code in the body of a Tag File tag!

The body-content of a Tag File defaults to “scriptless”, so you don’t have to declare body-content unless you want one of the OTHER two options: “empty” (nothing in the tag body) or “tagdependent” (treats the body as plain text).

Inside the Tag File with a tag directive (Header.tag)

image with no caption

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