By: Sathya Narayana in JSP Tutorials on 2010年10月24日 [フレーム]
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.
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"
%>
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 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 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" }
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
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:
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.
Most Viewed Articles (in JSP )
Show a calendar for user input in JSP
Encrypting Passwords in Tomcat using Servlets
JSP Tags for SQL to connect to a database
Steps to get a Free SSL certificate for your Tomcat
Uploading a file to a server using JSP
Server Side Programming using JSP
Latest Articles (in JSP)
Show a calendar for user input in JSP
Steps to get a Free SSL certificate for your Tomcat
Encrypting Passwords in Tomcat using Servlets
JSP Tags for SQL to connect to a database
Uploading a file to a server using JSP
Uploading an Image to a Database using JSP
A JSP page that gets properties from a bean
Scriptlets and Expressions in JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Show a calendar for user input in JSP
Encrypting Passwords in Tomcat using Servlets
Steps to get a Free SSL certificate for your Tomcat
JSP Tags for SQL to connect to a database
Uploading an Image to a Database using JSP
Uploading a file to a server using JSP
© 2023 Java-samples.com
Tutorial Archive: Data Science React Native Android AJAX ASP.net C C++ C# Cocoa Cloud Computing EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Trends WebServices XML Office 365 Hibernate
Latest Tutorials on: Data Science React Native Android AJAX ASP.net C Cocoa C++ C# EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Cloud Computing WebServices XML Office 365 Hibernate