1. Compile an implementation class that implements the tag Interface
2. Describe the tag processor class in the tld file (under the WEB-INF directory)
You can copy and modify the xml code in E: \ study \ tomcat \ apache-tomcat-7.0.22 \ apache-tomcat-7.0.22 \ webapps \ examples \ WEB-INF \ jsp2
Class3g. tld
<? Xml version = "1.0" encoding = "UTF-8"?>
<Taglib xmlns = "http://java.sun.com/xml/ns/j2ee"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemaLocation = "http://java.sun.com/xml/ns/j2eehttp://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
Version = "2.0">
<Description> There are my custom tags. </description>
<Tlib-version> 1.0 </tlib-version>
<Short-name> Class3g </short-name>
<Uri> http://www.class3g.com </uri>
<Tag>
<Description> showthe romete address </description>
<Name> viewIP </name>
<Tag-class> class3g. web. tag. ViewIpTag </tag-class>
<Body-content> empty </body-content>
</Tag> www.2cto.com
</Taglib>
3. import and use custom tags in jsp
<% @ Taglib uri = "http://www.class3g.com" prefix = "class3g" %>
Lifecycle of the TagSupport class
Create a tag processing object, then store the property value of the custom tag to the tag processing object, pass the value in, call the doStartTag () method, doStartTag () if the method returns the SKIP_BODY TAG body, it will not be executed and will directly go to the doEndTag () method. If the doEndTag () method returns EVAL_PAGE, you need to focus on other content of the JSP webpage, if SKIP_PAGE is returned, other content of the JSP page is ignored. If the doStartTag () method returns EVAL_BODY_INCLUDE, the TAG body is executed. If the doAfterBoda () method is not overwritten, The SKIP_BODY is returned. The TAG body is displayed once and then the doEndTag () method is run; if doAfterBoda () is overwritten, after the label content is displayed for the first time, EVAL_BODY_AGAIN is returned, and the subject content is re-displayed until SKIP_BODYZ is returned to run the doEndTag () method.
Author: Cheng Long