JSP自定义标签_用简单标签控制标签体执行10次
什么也不说,直接上代码:
import java.io.IOException; import javax.servlet.jsp.JspException; import javax.servlet.jsp.tagext.JspFragment; import javax.servlet.jsp.tagext.SimpleTagSupport; //控制标签执行10次 public class SimpleTagDemo2 extends SimpleTagSupport { @Override public void doTag() throws JspException, IOException { JspFragment jf = this.getJspBody(); for(int i=0;i<10;i++){ jf.invoke(null); } } }
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@taglib uri="/simpleitcast" prefix="itcast" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>用简单标签控制标签体执行10次</title> </head> <body> <itcast:demo2> xxxx<br/> </itcast:demo2> </body> </html>
<tag> <name>demo2</name> <!-- 为标签处理器类配一个标签名 --> <tag-class>cn.itcast.web.simpletag.SimpleTagDemo2</tag-class> <body-content>scriptless</body-content> </tag>