什么也不说,直接上代码:
import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.Tag; import javax.servlet.jsp.tagext.TagSupport; //控制jsp页面是否执行 public class TagDemo2 extends TagSupport { @Override public int doEndTag() throws JspException { //return Tag.SKIP_PAGE; //余下jsp不会执行 return Tag.EVAL_PAGE; } }
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@taglib uri="/itcast" prefix="itcast" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>控制标签体是否执行</title> </head> <body> <itcast:demo1> xxxx </itcast:demo1> </body> </html>
<!--tld文件配置代码--!>
<tag> <name>demo2</name> <tag-class>cn.itcast.web.tag.TagDemo2</tag-class> <body-content>empty</body-content> </tag>