Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

JSP tags let a page invoke reusable actions through markup-like syntax rather than embedding all its behavior in scriptlets. To use them, a JSP declares a tag library with a taglib directive, assigns it a prefix, and calls its actions with that prefix. For common page tasks, use JSTL; for project-specific behavior, choose a tag file or Java tag handler based on how the action should be authored and maintained.

What JSP tags do

A tag library extends the actions available in a JSP page. Its library description identifies the actions and how they are used; an implementation may be a JSP tag file or a Java tag handler. The JSP container translates the page and invokes the relevant action when the page runs. The Jakarta Server Pages API describes tag library components and runtime handlers at jakarta.servlet.jsp.tagext.

The directive connects a library URI to a prefix used within that page:

<%@ taglib prefix="c" uri="library-URI-for-your-version" %>
<c:if test="${condition}">Content shown when true</c:if>

The prefix is a local name chosen by the page author; it is not the library itself. Replace the example URI with the one required by the library and platform version in the application. If the JSP container cannot locate the referenced tag library description, translation fails.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When to use JSTL, a tag file, or a Java handler

Approach Good fit How it is authored and run
JSTL Standard page tasks such as conditions, iteration, formatting, internationalization, and EL functions. A standardized set of libraries and functions used through a taglib directive. The JSTL 2.0 specification requires a Jakarta Server Pages 3.0 web container.
Tag file A reusable presentation fragment or action that is natural to express in JSP syntax. Written with JSP syntax, so a Java tag handler is not required. JSP 3.1 documents tag files as a feature available since JSP 2.0.
Java tag handler A custom action whose behavior is best implemented in Java. Implemented as a handler class and exposed through a tag library; the container manages and invokes the handler during JSP execution.

JSTL is specified in the Jakarta Standard Tag Library 2.0 specification. The tag-file model and JSP extension mechanisms are described in the Jakarta Server Pages 3.1 specification.

Check compatibility before copying a taglib directive

JSP and tag-library conventions span generations of Java EE and Jakarta EE. The JSTL 2.0 specification lists the historical http://java.sun.com/jsp/jstl/... library URIs and states its JSP 3.0 container requirement; that does not establish that the same URI or dependency is correct for every later library implementation or container.

  1. Identify the application’s JSP version and the server/container version it actually runs.
  2. Check which JSTL API and implementation are included or required by that environment.
  3. Use the library URI documented for that specific combination, rather than assuming a tutorial’s prefix or URI is universal.
  4. Deploy and translate the JSP to confirm that the container resolves the tag library.

A framework can also provide its own tag libraries. For example, Apache Struts documents framework-specific JSP tags and directive usage; its prefix and library setup are examples for Struts, not requirements for JSP generally. See Apache Struts tag documentation.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose a custom-tag implementation

Use a tag file for JSP-authored reusable presentation

A tag file is a practical choice when the action is mostly presentation and the team wants to define it using JSP syntax. It lets page authors package a reusable action without implementing a Java handler class.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a Java tag handler for Java-centric behavior

Choose a handler when the action is more naturally implemented in Java and should be exposed as a custom JSP action. The container manages the handler object and evaluates the action during JSP execution, as described in the JSP tag extension API.

Keep responsibilities clear

Prefer tags for reusable presentation behavior; keep broader business rules and application data work in appropriate application layers. A tag library can make a page easier to read, but it should not become a hidden home for unrelated business logic.

What to do when a tag does not work

  • Translation reports an unresolved tag library: check the directive’s URI, the dependency or library packaging, and whether the container supports the relevant JSP generation.
  • A tutorial’s URI fails on a newer application: verify the library’s version-specific documentation rather than changing only the prefix. The prefix is an alias; the URI identifies the library.
  • A custom action feels difficult to maintain: reconsider whether it is a JSP-authored presentation fragment better suited to a tag file, or Java behavior better suited to a handler.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.