

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An overview of jsp tag files, their implementation using simple tag handlers, and the use of directives such as taglib, include, tag, attribute, and variable. It also includes examples of simple and complex tag files, and the evaluation of fragments passed to tag files.
Typology: Slides
1 / 25
This page cannot be seen from the preview
Don't miss anything!


















<%@ taglib prefix="my" uri="/mytags" %> <my:repeat num="3"> tag body </my:repeat>
void doTag() { for( int i = 0; i < num; i++ ) { getJspBody().invoke( null ); } }
SimpleTag
SimpleTagSupport
setNum() doTag()
RepeatHandler
Usage
Implementation
This slide shows repeat tag implementation using Simple Tag handler of JSP 2.0. Here the RepeatHandler simply extends SimpleTagSupport class , which itself is an implementation of SimpleTag interface.
Now using simple tag handler, all you have to implement is doTag() method in which you JspFragment object by calling getJspBody() method and then invoke(null) method in order to spit out the JspFragment to the output writer.
Tag files is another significant improvement of JSP 2.0.
Simple yet flexible packaging Just drop a .tag file in /WEB-INF/tags/ Implicit tag library automatically generated Or, write a .tld for added flexibility ` Or, package in a JAR with a .tld
Another important feature of tag file is that it enables simpler deployment than class Java tag handler model. That is, in order deploy tag files, all you have to do is to drop tag files in /WEB‐INF/tags directory. The container is then deploy the tag files by creating implicit tag library. If more flexible deployment is desired, then you can still create TLD file.
Identifies the location of the tag files Value of it must start with /WEB-INF/tags/ Syntax <%@ taglib prefix="tt" tagdir=/WEB-INF/tags/dir %>
Tag file concept is introduced in JSP 2.0. Tag file is tag handler implementation in JSP syntax as opposed to using Java programming language.
The value of tagdir attribute starts with /WEB‐INF/tags as shown in the slide above.
description name required rtexprvalue type fragment (default is false) if true, container fixes the rtexprvalue attribute at true the type attribute at javax.servlet.jsp.tagext.JspFragment Otherwise, it is a normal attribute to be evaluated by the container prior to being passed to the tag handler
Example 1: Simple Attribute (panel.tag) <%@ attribute name="color" %> <%@ attribute name="bgcolor" %> <%@ attribute name="title" %>
| ${title} |
| |
The Duke's Bookstore shipDate tag, defined in shipdate.tag, is a custom tag with a simple attribute. The tag generates the date of a book order according to the type of shipping requested. The tag determines the number of days until shipment from the shipping attribute passed to it by the page bookreceipt.jsp. From the days, the tag computes the ship date. It then formats the ship date.
| | Second panel. Second panel. Second panel. | |