The taglib, tag, include, attribute and the variable Directive in JSP
By: Sathya Narayana in JSP Tutorials on 2010-10-24
The taglib Directive
A tag library is a collection of tags used to extend a JSP container functional model. The taglib directive defines a tag library namespace for the page, mapping the uniform resource indicator (URI) of the tag library descriptor to a prefix that can be used to reference tags from the library on this page.
<%@ taglib (uri="tagLibraryURI" | tagdir="tagDir") prefix="tagPrefix" %>
.
.
.
<tagPrefix:tagName attributeName="attributeValue" >
JSP content
</tagPrefix:tagName>
<tagPrefix:tagName attributeName="attributeValue" />
You can assume that the tag library descriptor (TLD) defines a tagName element. tagdir indicates this prefix is for identifying tag extensions installed in the /WEB-INF/tags/ directory or a subdirectory. If a TLD is present in the specified directory, it's used. Otherwise, an implicit tag library descriptor, generated by the container, is used. A translation error must occur if the value doesn't start with /WEB-INF/tags/. A translation error must occur if the value doesn't point to a directory that exists. A translation error must occur if used in conjunction with the uri attribute.
The tag Directive
You can use most JSP directives in simple tag handler code files. Note that the page directive itself isn't used; instead, you use the tag directive, which may only be used in tag files. Here's the syntax:
<%@ tag tag_directive_attr_list %>
tag_directive_attr_list ::=
{ display-name="display-name" }
{ body-content="scriptless|tagdependent|empty" }
{ dynamic-attributes="name" }
{ small-icon="small-icon" }
{ large-icon="large-icon" }
{ description="description" }
{ example="example" }
{ language="scriptingLanguage" }
{ import="importList" }
{ pageEncoding="peinfo" }
{ isELIgnored="true|false" }
This is an example tag directive:
<%@ tag name="msg"
display-name="Message"
body-content="scriptless"
dynamic-attributes="user"
small-icon="/WEB-INF/small-icon.jpg"
large-icon="/WEB-INF/large-icon.jpg"
description="Simple usage of a tag directive"
%>
The include Directive
There are two include tags: the include directive and the jsp:include action.
The include directive includes a static file at translation time, adding any JSP in that file to this page for run-time processing:
<%@ include file="header.html" %>
The attribute Directive
The attribute directive is analogous to the <attribute> element in the TLD and allows you to declare custom action attributes. This is the syntax:
<%@ attribute attribute_directive_attr_list %>
attribute_directive_attr_list ::=
name="attribute-name"
{ required="true|false" }
{ fragment="true|false" }
{ rtexprvalue="true|false" }
{ type="type" }
{ description="description" }
The variable Directive
The variable directive is analogous to the <variable> element in the TLD and allows you to define a variable exposed by the tag handler. This is the syntax:
<%@ variable variable_directive_attr_list %>
variable_directive_attr_list ::=
( name-given="output-name" |
( name-from-attribute="attr-name" alias="local-name"))
{ variable-class="output-type" }
{ declare="true|false" }
{ scope="AT_BEGIN|AT_END|NESTED" }
{ description="description" }
Add Comment
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
- Your name, rating, website address, town, country, state and comment will be publicly displayed if entered.
- Aside from the data entered into these form fields, other stored data about your comment will include:
- Your IP address (not displayed)
- The time/date of your submission (displayed)
- Your email address will not be shared. It is collected for only two reasons:
- Administrative purposes, should a need to contact you arise.
- To inform you of new comments, should you subscribe to receive notifications.
- A cookie may be set on your computer. This is used to remember your inputs. It will expire by itself.
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
- Although the administrator will attempt to moderate comments, it is impossible for every comment to have been moderated at any given time.
- You acknowledge that all comments express the views and opinions of the original author and not those of the administrator.
- You agree not to post any material which is knowingly false, obscene, hateful, threatening, harassing or invasive of a person's privacy.
- The administrator has the right to edit, move or remove any comment for any reason and without notice.
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
- Data Science
- Android
- React Native
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
Comments