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

Tag Files: like include, only better

With Tag Files, you can invoke reusable content using a custom tag instead of the generic <jsp:include> or <c:import>. You can think of Tag Files as a kind of “tag handler lite”, because they let page developers create custom tags, without having to write a complicated Java tag handler class, but Tag Files are really just glorified includes.

Simplest way to make and use a Tag File

  1. Take an included file (like “Header.jsp”) and rename it with a .tag extension.

    image with no caption
    image with no caption
  2. Put the tag file (“Header.tag”) in a directory named “tags” inside the “WEB-INF” directory.

    image with no caption
  3. Put a taglib directive (with a tagdir attribute) in the JSP, and invoke the 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