JSP自定义业务标签
自定义标签:
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; } }
<?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:
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。