The first step is to do a class that derives from the Simpletagsupport, "alt+/" option to override the Dotag () method.
Public classTesttagextendsSimpletagsupport {PrivateString outertagname= "P"; Public voidsetoutertagname (String outertagname) { This. Outertagname =Outertagname; } Private intcount; Public voidSetCount (intcount) { This. Count =count; } @Override Public voidDotag ()throwsjspexception, IOException {jspfragment Frag= This. Getjspbody ();//the currently generated fragment This. Getjspcontext (). Getout (). Write ("<" +outertagname+ ">");//Added Properties for(inti=0;i<count;i++) {Frag.invoke (NULL);//Build Output } This. Getjspcontext (). Getout (). Write ("</" +outertagname+ ">"); }}
Step Two, configure
Create a new Xml.file file in the Web-inf folder, change the extension to TLD, select the XML template, and complete the creation.
Taglib as the root element
<taglib xmlns= "Http://java.sun.com/xml/ns/javaee" xmlns:xsi= "http://www.w3.org/2001/ Xmlschema-instance " xsi:schemalocation=" Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ Ns/javaee/web-jsptaglibrary_2_1.xsd " version=" 2.1 ">
A description of the entire file is written under the root element
<description> Custom Jstl Tags </description> description
<display-name>jstl Custom Labels </display-name> display names
<tlib-version>1.1</tlib-version> version
<short-name>c</short-name> prefixes
<uri>http://www.itnba.com/maya/myjstl</uri> Unique identification
<description> Customize Jstl Tags </description> <display-name>jstl custom Labels </display-name> <tlib-version>1.1</tlib-version> <short-name>c</short-name> <uri>http://www.itnba.com/maya/myjstl</uri>
Back write <tag> Label
<name>catch</name> quote: That's the name behind it.
<tag-class>com.itnba.maya.myel.TestTag</tag-class> Com.itnba.maya.myel is the first step to do the package name Testtag is the class name
<body-content>scriptless</body-content> cannot write scripts, i.e. cannot write <%%>
<required>false</required> is required, true is auto generate must fill, false can write not write
<rtexprvalue>false</rtexprvalue> can I use El expressions <tag>
<tag> <description>..... Description</description> <name>Catch</name> <tag-class>com.itnba.maya.myel.testtag</tag-class> <body-content>scriptless</body-content> <attribute> <description>First Property</description> <name>outerTagName</name> <required>false</required> <rtexprvalue>false</rtexprvalue> </attribute> <attribute> <description>Second Property</description> <name>count</name> <required>false</required> <rtexprvalue>false</rtexprvalue> </attribute> </tag></taglib>
In the third step, you can now refer to this JSTL custom label.
Pilot the El function written,
Prefix is the name used in ${}, and the URI is the unique identity in the second-step configuration
<%@ taglib prefix= "C" uri= "Http://www.itnba.com/maya/myjstl"%>
Use the prefix name:<tag> in <name>, and then you can add the written property
<c:catch outertagname= "H3" count= "2" >Hello Lee<br></c:catch>
This code should display the number third title, Count is the number of cycles, two times, as shown.
Package Jstl Custom Labels yourself