The taglib, tag, include, attribute and the variable Directive in JSP

By: Sathya Narayana Emailed: 1768 times Printed: 2517 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

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" }

JSP Home | All JSP Tutorials | Latest JSP Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(1)


1. View Comment

Pls put all this code in one folder(Full project directory) and make zip it and give option to download (with all lib .jar). it will more helpfull for understand .

View Tutorial          By: Guruprasada at 2011-09-15 07:27:57

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Sathya Narayana
Querying Data with the JSTL in JSP
Deleting Data in MySQL
Modifying data and using WHERE clause in MySQL
Querying the Database in MySQL
Inserting Data into Tables in MySQL
Changing the Structure of an Existing Table in MySQL
The Exception Object in JSP
The Application Object in JSP
The Session Object in JSP
The Out Object in JSP
The Response Object in JSP
The Request Object in JSP
Tag Libraries in JSP
Scriptlets and Expressions in JSP
Declarations in JSP

More Tutorials in JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: `java.net.BindException: Permission denied <null>:80
JSP Alert Example
JSP CheckBox Example
Uploading an Image to a Database using JSP
Uploading a file to a server using JSP
A JSP page that gets properties from a bean
The page Directive in JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Declarations in JSP
Scriptlets and Expressions in JSP
Tag Libraries in JSP
The Request Object in JSP
The Response Object in JSP
The Out Object in JSP
The Session Object in JSP

More Latest News
Most Viewed Articles (in JSP )
What are the different scopes in JSP?
JSP Example to connect to MS SQL database and retrieve records
Sending Email using JSP
Automatically Refreshing a JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: `java.net.BindException: Permission denied <null>:80
The JSP Program running first Time.
Embedding java codes in jsp sciptlets
JSP Program for display Date
HttpClient
The Advantages of Servlets Over “Traditional” CGI
The Servlet Life Cycle
ENTERPRISE JAVA BEANS:
Enabling Expression Language Evaluation in JSP
Deploying an Individual JSP on Tomcat
The page Directive in JSP
Most Emailed Articles (in JSP)
What is JSP?
Declaring variable in JSP
Techniques for form editing
A Simple Servlet Generating Plain Text
An Example Using Servlet Initialization and Page Modification Dates
HttpClient
Servlets
Text Object
The Basic Syntax Expression Language in JSP
Disabling Scriptlets in JSP using web.xml
The BodyTag Interface in JSP
What are the different scopes in JSP?
Sending Email using JSP
Using a DataSource from WebLogic in a JSP
Getting HTTP Request Headers in a JSP