JSP custom tag label [c]

1. Markup Language Features

<开始标签 属性="属性值">标签体</结束标签>
   空标签
   <br/><hr/>
   <开始标签></结束标签>
   <开始标签/>
   ui标签
   控制标签
   数据标签

2. Custom label development and use steps

1, create a label helper class (inherited BodyTagSupport)
tag attributes must attribute the corresponding helper class, and to provide the corresponding get / set methods
rtexprvalue

2. Create a tag library descriptor (tld), add a custom tag configuration
Note: tld files must be saved to the WEB-INF directory or its subdirectories

3, in JSP tag library by introducing taglib directive, and by specifying a suffix
to access custom label

Why in the custom tag?

In some labels do not meet the requirements of the code of our time, this time on the need to define ourselves.

    
  <description>zking 1.1 core library</description>
  <display-name>zking core</display-name>
  <tlib-version>1.1</tlib-version>
  <short-name>c</short-name>
  <uri>/zking</uri>
  
  <tag>
  <!-- 标签库里面的标签名 -->
    <name>demo</name>
   <!-- 标签对应的助手类的全路径名 -->
    <tag-class>com.zking.jsp.day01.DemoTag</tag-class>
  <!-- jsp -->
    <body-content>JSP</body-content>
    <attribute>
    <!-- 属名    可以有多个 -->
        <name>test</name>//属性名是需要私有化的在下面会用到
        <!-- 属性值是否必填 -->
        <required>false</required>
        <!-- 是否使用表达式 -->
        <rtexprvalue>false</rtexprvalue>
    </attribute>
  </tag>

 </taglib> 

Three ways to do at what time?

  1. By default, if the tag body jsp above, then the three methods will be executed
  2. If there is no tag body, then the method does doAfterBody
  3. Which is the default setting
  4. At this time, the label body jsp, artificially doStartTag return value to SKIP_BODY, and then not performed doAfterBody jsp pages based content display body
  5. If you change doAfterBody Mo recognize the return value EVAL_BODY_AGAIN, then repeatedly execute doAfterBody

3. Label Lifecycle

Let's talk about its life cycle, its life cycle is only in this interface.

  1. doStartTag () start tag
  2. The doAfterBody () body portion
  3. doEndTag () end tag
  <description>zking 1.1 core library</description>
  <display-name>zking core</display-name>
  <tlib-version>1.1</tlib-version>
  <short-name>c</short-name>
  <uri>/zking</uri>

  <tag>
  <!-- 标签库里面的标签名 -->
    <name>demo</name>
   <!-- 标签对应的助手类的全路径名 -->
    <tag-class>com.zking.jsp.day01.DemoTag</tag-class>
  <!-- jsp -->
    <body-content>JSP</body-content>
    <attribute>
    <!-- 属名    可以有多个 -->
        <name>test</name>//属性名是需要私有化的在下面会用到
        <!-- 属性值是否必填 -->
        <required>false</required>
        <!-- 是否使用表达式 -->
        <rtexprvalue>false</rtexprvalue>
    </attribute>
  </tag>

 </taglib> 

Its operation method, a flowchart is as follows:
Here Insert Picture Description

Its return value:

  SKIP_BODY:            跳过主体
  EVAL_BODY_INCLUDE:    计算标签主体内容并[输出]
  EVAL_BODY_BUFFERED:   计算标签主体内容并[缓存]
  EVAL_PAGE:             计算页面的后续部分
  SKIP_PAGE:             跳过页面的后续部分
  EVAL_BODY_AGAIN:       再计算主体一次

To learn more contact the blogger, thank you watch.

Guess you like

Origin blog.csdn.net/zyp_baoku/article/details/90713670