simpletagdemo.java

来自「此资源是jsp应用开发 邓子云等编写的一书里的源代码」· Java 代码 · 共 39 行

JAVA
39
字号
/**
 * 
 */
package customtag;
import javax.servlet.jsp.tagext.*;
import java.io.*;
import java.util.*;
import javax.servlet.jsp.*;

/**
 * @author Administrator
 *
 */
public class SimpleTagDemo extends SimpleTagSupport {
	private int num;

	public void setNum(int num) {
		this.num = num;
	}

	/**
	 * Called by the container to invoke this tag.
	 *
	 * @throws JspException If an error occurred while processing this tag.
	 * @throws IOException If there was an error writing to the output
	 *   stream.
	 * @todo Implement this javax.servlet.jsp.tagext.SimpleTag method
	 */
	public void doTag() throws JspException, IOException {
		JspWriter out = this.getJspContext().getOut();
		out.println("<h1>演示" + num + "次输出标签体的内容</h1>");
		for (int i = 0; i < num; i++) {
			getJspContext().setAttribute("count", String.valueOf(i + 1));
			getJspBody().invoke(null);
		}
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?