Write your own custom tag library operating principle (4)

By reading the three articles before, already can handle your own custom tag libraries, but if not familiar with the operation principle of custom tag, if you encounter an error may be confused, this article will introduce the operation principle of custom tag.

1.JspTag Interface

Achieved the previous instance TagSupport class, and there is no direct use JspTag interface, but in fact tag handling class must be achieved JspTag interfaces. JspTag interface definition in javax.servlet.jsp.tagext package, it is just a marking interface does not define any methods, all tag handling class must implement this interface.

javax.servlet.jsptagext package also includes IterationTag interfaces, BodyTag interfaces, SimpleTag interfaces, TagSupport class, BodyTagSupport class and simpleTagSupport class, inheritance relation between them is as follows:

JspTag Interface


----------- Tag Interface

| |

| ---------- IterationTag Interface

| |

| --------------------- TagSupport class

| | |

| ---------------- BodyTag Interface |

| | |

| --------- BodyTagSupport class


----------- SimpleTag Interface


-------- SimpleTagSupport class

Tag interface:

This interface defines the write tag address classes to achieve the basic methods, including what methods: doStartTag (), doEndTag (), getParent (), release () and setPageContext () method, which doStartTag () and doEndTag () method is the most commonly used method. doStartTag () method in the implementation of the custom tag is called when the start tag, doEndTag () method in the implementation of the custom tag's end tag is called.

Tag in the actual preparation of the class when dealing with the general without directly implement this interface, usually inherit this interface has been achieved or BodyTagSupport TagSupport class.

IterationTag interface:

This interface inherits from the Tag interface and adds a new doAfterBody () method, this method can generally achieve the contents of custom tag that contains the cycle of operation.

doAfterBody () method only if the doStartTag () method returns a value of EVAL_BODY_INCLUDE only when called. Call doAfterBody () method, if the return value is EVAL_BODY_AGAIN, it will again run the custom tag that contains the content and once again call doAfterBody () method until the doAfterBody () method returns a value of SKIP_BODY, so that to realize the custom tag contains operational content.

TagSupport categories:

This class is the most commonly used preparation of custom tag class, in fact it is a helper class that can help us to quickly write tag handler class, he realized IterationTag interfaces. We write tag handler class can inherit the class time, rewrite the way they need, without the need to directly interface to achieve IterationTag or Tag. The design model used here the default adapter mode.

An inherited class that TagSupport tag handling custom tag this tag can display the content contained, but can not edit the contents contained in and transform. If you need to edit the contents contained in the need to inherit BodyTagSupport class

TagSupport class call process is as follows:

分类:Web 时间:2010-04-08 人气:228
blog comments powered by Disqus


  • Jsp / Servlet Chapter 9 review notes ----- custom tag JSP Standard Tag Library and 2010-10-26

    Tag Library: Reason: In the development of JSP, MVC design pattern in the standard, I hope as much as possible not to appear Scriplet (< %....%>), Provided in the JSP tag library called the code, this code can solve the JSP code appears Scriplet sit

  • Write your own custom tag library 2010-04-06

    We all know that by using the JSP tag library in the display layer can reduce the Java code to make the modification, maintenance, and reading them is more convenient. <% String format ="yyyy-MM-dd HH:mm:ss"; SimpleDateFormat sdf = new Simple

  • JSTL-core tag library 2010-11-12

    JSTL full name of the Java Server Pages Standard Tag Library (JSP Standard Tag Library), it is the Chinese name of the JSP Standard Tag Library. Web application developers can use JSTL and EL to develop Web program to replace the traditional embedded

  • JSTL Xiang Jie - Core tag library 2010-05-07

    There are following in JSTL1.1 tag library are supported: Core tag library, XML processing tag library, I18N formatting tag library, Database access tag library, Functions tag library. Table 2 shows the corresponding identifier: Table 2 tag library U

  • struts tag library of the bean: write usage 2011-05-30

    First, in order to use the struts tag library, you must be specified in the jsp tag library used to uri, that is the standard tag library. Introduced as follows: <% @ Taglib prefix = "bean" uri = " http://struts.apache.org/tags-bean &quo

  • Provided using JSP 2 SimpleTagSupport development of custom label (taken from the IBM developerWorks China) 2010-07-07

    Description: Most areas of the MVC framework for Java, such as Struts, Spring MVC, JSF, are mainly composed of two parts: the controller components and view components. One view components mainly by a large number of feature-rich tag library as. For

  • JSP tag library in-depth study 2010-07-14

    Tag handler and tag additional information needs to be positioned in the JSP container class loader can find it. Tag library descriptor can be specified in the URL location of the symbol means. Taglib Tag library Tags are defined and distributed in a

  • jsp custom tag library 2010-10-03

    1. Why should I use a custom label? Mainly to replace the ugly JSP script. Inserted in the HTML page has the following disadvantages of JSP scripts: JSP script is ugly, difficult to read. JSP scripts and HTML code for mixed and high maintenance costs

  • Java programmer to master the 10 in the JSP tag library, you know a few? 2008-10-09

    JSP a feature of the easiest of negligence is that it can be applied to use the new block of code - aka "tag library" - to a JSP application to add new functions of the French. These types of signs claiming the use of XML tag library supplied ca

  • jstl (jsp standard tag library), introduced 2010-04-14

    jstl (jsp standard tag library) description of: a young master (shaoye@dev-club.com) Preface Jsp 1.1 specification from the start, jsp has supported the jsp in the Use custom defined tags, and extensive use of custom labels created a programmer to re

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.131 (s). 12 q(s)