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:
- Ensure that the tag library's JAR file is on the web application's classpath, as
described in
Managing the Classpath.
- 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"%>
- The uri attribute shows the location of the tag library and should be unique within the web application.
The uri can either be the URI specified by the TLD file, or the uri can
be the location of the TLD file in the WEB-INF folder, if the uri
element is missing in TLD file. When you type the uri attribute, press Ctrl-Space after you
type the first quotation mark. The IDE shows the list of URIs for available
tag libraries.
- The prefix attribute is used to identify tags from the library. The TLD file
usually recommends a prefix, but you can use any prefix you want.
- 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:
- Ensure that the tag library's JAR file is on the web application's classpath, as
described in
Managing the Classpath.
- 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" %>
- The tagdir attribute shows the location
of the tag library within the web application.
- The prefix attribute is used to identify
tags from the library. The tag file usually recommends a prefix, but you
can use any prefix you want.
- 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:
- 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:

- 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