JSP custom tag simple tutorial

There is the following paragraph in sun's official documents.

Official document statement

Life cycle and call process

The following is a non-normative,brief overview of the SimpleTag lifecycle. Refer to the JSP Specification for details.

A new tag handler instance is created each time by the container by calling the provided zero-args constructor. Unlike classic tag handlers,simple tag handlers are never cached and reused by the JSP container. The setJspContext() and setParent() methods are called by the container. The setParent() method is only called if the element is nested within another tag invocation. The setters for each attribute defined for this tag are called by the container. If a body exists,the setJspBody() method is called by the container to set the body of this tag,as a JspFragment. If the action element is empty in the page,this method is not called at all. The doTag() method is called by the container. All tag logic,etc. occur in this method. The doTag() method returns and all variables are synchronized.

Simple label use case

Must know and know: a simple tag is also a tag, so the declaration process is the same as that of tag, which is also a three-step process.

1. Build an implementation class that inherits the simpletag class, rewrite the dotag method, 2. Strictly declare in the TLD file, 3. Declare the taglib namespace and tag prefix in the JSP page, and then call the custom simple tag

Step 1: create an implementation class:

Configure related constraint items in TLD file:

The third step: declare in the JSP page and then call:

Summary: the simple tag can replace the bodytag interface to complete the same operation, but it is simpler and lighter. The lifecycle logic of the simple tag is clear, and the calling rules are clear. The manipulation of the tag body can be completed by using the relevant flow object

The above is the whole content of this article. I hope it will be helpful to your study.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>