带标签体标签

 
<tag>
		<!-- 定义标签名 -->
		<name>iterator</name>
		<!-- 定义标签处理类 -->
		<tag-class>lee.IteratorTag</tag-class>
		<!-- 定义标签体不允许出现JSP脚本 -->
		<body-content>scriptless</body-content>
		<!-- 配置标签属性:collection -->
		<attribute>
			<name>collection</name> 
			<required>true</required>
			<fragment>true</fragment>
		</attribute>
		<!-- 配置标签属性:item -->
		<attribute>
			<name>item</name> 
			<required>true</required>
			<fragment>true</fragment>
		</attribute>
	</tag>

public class IteratorTag extends SimpleTagSupport
{
	//标签属性,用于指定需要被迭代的集合
	private String collection;
	//标签属性,指定迭代集合元素,为集合元素指定的名称
	private String item;
	
	//collection属性的setter和getter方法
	public void setCollection(String collection)
	{
		this.collection = collection;
	}
	public String getCollection()
	{
		return this.collection;
	}
	//item属性的setter和getter方法
	public void setItem(String item)
	{
		this.item = item;
	}
	public String getItem()
	{
		return this.item;
	}
	//标签的处理方法,简单标签处理类只需要重写doTag方法
	public void doTag() throws JspException, IOException
	{
		//从page scope中获取属性名为collection的集合
		Collection itemList = (Collection)getJspContext().
			getAttribute(collection);
		//遍历集合
		for (Object s : itemList)
		{
			//将集合的元素设置到page 范围
			getJspContext().setAttribute(item, s );
			//输出标签体
			getJspBody().invoke(null);
		}
	}
}

<mytag:iterator collection="a" item="item">
		<tr>
			<td>${pageScope.item}</td>
		<tr>
		</mytag:iterator>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值