1. To develop a custom behavior, you need to use a series of classes and interfaces called tag extension mechanisms in JSP1.1 specifications ). All interfaces and classes required to implement the tag Handler are defined in the javax. servlet. jsp. tagext package. The two main interfaces are Tag and BodyTag. To make the development of the tag handler easier, the API defines two supported classes: TagSupport and BodyTagSupport. These two classes provide the default implementation for the above two interfaces respectively.
2. The tag library is a set of custom rows. In addition to marking handler class files, the tag library must also include a tld file. This is an XML file that maps all custom row names to corresponding tag handler classes and describes all attributes supported by each custom behavior. Class files and tld files can be packaged into a JAR file for easy installation.
3. Development, configuration, and use of a simple custom behavior usually need to do this work.
(1) implement a tag handler class. Compile the class and place the generated class file under the WEB-INF/classes directory of the application.
(2) create a TLD file. Let's look at the simple example below.
<? Xml version = "1.0" encoding = "ISO-8859-1"?>
<! DOCTYPE taglib
PUBLIC "-// Sun Microsystems, Inc. // dtd jsp Tag Library 1.1 // EN"
Http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd>
<Taglib>
<Tlibversion> 1.0 </tlibversion>
<Jspversion> 1.1 </jspversion>
<Shortname> test </shortname>
<Tag>
<Name> hello </name>
<Tagclass> com. mycompany. HelloTag </tagclass>
<Bodycontent> empty </bodycontent>
<Attribute>
<Name> name </name>
</Attribute>
</Tag>
</Taglib>
Name the file *. tld and place it in the application's WEB-INF/tlds directory.
(3) Now you can use custom behaviors on the JSP page.
<% @ Taglib uri = "/WEB-INF/tlds/mylib. tld" prefix = "test" %>
<Html>
<Body bgcolor = "white">
<Test: hello name = "maojb"/>
</Body>
</Html>
When this page is requested, the JSP Container uses this TLD to find the class corresponding to the custom behavior. It then calls all corresponding methods and adds the corresponding text to the response. The above is all we have to do in the simplest case.