JSP自訂業務標籤

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   java   io   檔案   ar   

自訂標籤:

package cn.hv.tag;import javax.servlet.jsp.JspException;import javax.servlet.jsp.JspWriter;import javax.servlet.jsp.tagext.BodyContent;import javax.servlet.jsp.tagext.BodyTagSupport;public class BodyTag extends BodyTagSupport {    private String model;    private int pc ;    public int doStartTag() throws JspException {        JspWriter out = pageContext.getOut();        return model.equals("yyt") ? super.EVAL_BODY_INCLUDE : super.SKIP_BODY;    }    public int doAfterBody() throws JspException {        if(pc > 0  ){            pc--;            return super.EVAL_BODY_AGAIN;        }        return super.SKIP_BODY;    }    public String getModel() {        return model;    }    public void setModel(String model) {        this.model = model;    }    public int getPc() {        return pc;    }    public void setPc(int pc) {        this.pc = pc;    }    }
View Code
<?xml version="1.0" encoding="UTF-8"?>  <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"         "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">  <taglib>      <tlib-version>1.0</tlib-version>      <jsp-version>1.2</jsp-version>      <short-name>c</short-name>      <tag>          <name>enable</name>          <tag-class>cn.hv.tag.BodyTag</tag-class>          <body-content>JSP</body-content>          <attribute>              <name>model</name>             <rtexprvalue>true</rtexprvalue>        </attribute>          <attribute>              <name>pc</name>             <rtexprvalue>true</rtexprvalue>        </attribute>     </tag>  </taglib>  
<jsp-config>        <taglib>            <taglib-uri>/web-html</taglib-uri>            <taglib-location>                /WEB-INF/web-html.tld            </taglib-location>        </taglib>    </jsp-config>

 以上就是自訂標籤:

web.xml :配置自訂的標籤檔案

EVAL_BODY_INCLUDE:顯示標籤體內

EVAL_BODY_AGAIN:

SKIP_BODY:

SKIP_PAGE:

 

JSP自訂業務標籤

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.