Using Tags in JSP Files

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 directory that contains tag files.

To use a tag from a tag library JAR file:

  1. Place the tag library JAR file under the WEB-INF/lib directory of the web module.
  2. Before referencing one of its tags in a JSP source file, add a taglib directive with URI and prefix attributes to the JSP file.
  3. At any point after the taglib directive, you can use the tag prefix to reference tags from the tag library. For example:
        <%@ taglib prefix="sql"
        uri="http://java.sun.com/jstl/ea/sql" %> 
        <sql:transaction dataSource="${myDatasource}"> 
        
tip  If the tag library is going through frequent changes and you use it in several web modules, you might not want to maintain several copies. In this case, you can put the JAR file in the ide-install-path/lib/ext directory and in the server's shared libraries directory. However, if the JAR file is not in the WEB-INF/lib directory, code completion will not work for the tags in that tag library.

To use a tag from a tag library directory:

  1. Place the tag library directory under the web module's WEB-INF/tags directory.
  2. Before referencing one of its tags in a JSP source file, add a taglib directive to the file. The directive requires a tagdir attribute for the location of the tag library within the web module and a tag prefix used to identify tags from that library. The tag file usually recommends a prefix, but you can use any prefix you want.
  3. At any point after the taglib directive, you can use the tag prefix to reference tags from the tag library. For example:
        <%@ taglib prefix="sql"
        tagdir="/WEB-INF/tags/sqltags" %> 
        <sql:transaction dataSource="${myDatasource}">
        
See Also
About Tag Libraries
Using Tag Libraries
Adding Tag Files to Web Modules
Creating TLD Files
Creating and Editing Tags
Deploying Tag Libraries
About JSP Syntax

Legal Notices