Accessing a Custom Tag from a JSP Page

See Also

The JavaServer Pages technology provides a set of standard action elements for performing actions on information. The <jsp:getProperty> element is an example of a commonly used action element. You can extend the set of action elements through custom tags that are defined in tag libraries, such as the JSTL tag library.

This topic shows how to use a tag from a tag library JAR file, and then shows how to use a tag from a tag library folder that contains tag files.

To access a custom tag from a tag library JAR file:

  1. Ensure that the tag library's JAR file is on the web application's classpath, as described in Managing the Classpath.
  2. Before referencing one of its tags in a JSP file, add a taglib directive with a uri and prefix attribute to the JSP file:
           <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
  3. At any point after the taglib directive, you can use the tag prefix to reference tags from the tag library. For example:
          <c:if test="${param.sayHello}">
    	 Hello ${param.name}!
          </c:if>

To access a custom tag from a tag library folder:

  1. Ensure that the tag library's JAR file is on the web application's classpath, as described in Managing the Classpath.
  2. Before referencing one of its tags in a JSP source file, add a taglib directive to the file:
           <%@ taglib tagdir="/WEB-INF/tags/" prefix="a" %>
  3. At any point after the taglib directive, you can use the tag prefix to reference tags from the tag library. For example:
           <a:mytagfile>abc</a:mytagfile>

To quickly locate a tag's source file:

  1. Hold down the Ctrl key and, at the same time, move your mouse over a tag in the JSP file.

    Notice that the Source Editor displays the tag as a hyperlink and that the cursor changes to a hand symbol:

    screenshot of hyperlink

  2. Click the hyperlink.

    The tag file referenced by the tag opens in the Source Editor.

See Also
About Tag Libraries
Creating a Tag File
Creating a TLD File
Creating a Tag Handler

Legal Notices