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

Customizing the included content with <jsp:param>

OK, so you’ve got a header that’s supposed to appear the same way on every page. But what if you want to customize part of the header? What if you want, say, a context-sensitive subtitle that’s part of the header, but that changes depending on the page?

You have a couple options.

The dumb way: put the subtitle information into the main page, as, say, the first thing in your page after the include for the header.

The smarter way: pass the subtitle information as a new request parameter to the included page!

Why that’s cool: if the subtitle information is supposed to be part of the header, but it’s a part that changes, you still want the header part of the template to make the decision about how that subtitle should appear in the final page. In other words, let the person who designed the header decide how the subtitle should be rendered!

JSP that does the include

image with no caption

The included header that USES the new param (“Header.jsp”)

image with no caption

Note

Note: this idea of params doesn’t make any sense with the include directive (which is not dynamic), so it applies ONLY to the <jsp:include> standard action.

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