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

To a Tag File, you don’t send request parameters, you send tag attributes!

You invoke a Tag File with a tag, and tags can have attributes. So it’s only natural that the Tag File developer might want to invoke the tag with attributes... attributes that get sent to the Tag File.

Invoking the tag from the JSP

Before (using <jsp:param> to set a request parameter)

<jsp:include page="Header.jsp">
   <jsp:param name="subTitle" value="We take the sting out of SOAP." />
</jsp:include>

After (using a Tag with an attribute)

<myTags:Header subTitle="We take the String out of SOAP" />

Using the attribute in the Tag File

image with no caption

Note

All tag attributes have TAG scope. That’s right, just the tag. Once the tag is closed, the tag attributes go out of scope!

You have to be clear about these—the <jsp:include> <jsp:param> value goes in as a request parameter. That’s not the same as a request-scoped attribute, remember. The name/value pair for the <jsp:param> looks to the web-app as though it came in with a form submission. That’s one of the reasons we DON’T like using it—the value you meant to pass ONLY to the included file, ends up visible to any component in the web app that is a part of this request (such as servlets or JSPs to which the request is forwarded).

But the nice, clean thing about tag attributes for Tag Files is that they’re scoped to the tag itself. Just be sure you know the implications. This will NOT work: ...

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