?? iteratetag.java
字號:
package com.jspdev.ch14;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
import java.util.*;
public class IterateTag extends BodyTagSupport
{
/**
*Tag的屬性
*/
private String name;
//
private Iterator it;
//type
private String type;
/**
*設置屬性collection
*/
public void setCollection(Collection collection)
{
if(collection.size()>0)
it=collection.iterator();
}
public void setName(String name)
{
this.name=name;
}
public void setType(String type)
{
this.type=type;
}
/**
*如果it屬性為null,那么忽略計算tagbody。
*/
public int doStartTag()throws JspTagException
{
if(it==null)
return SKIP_BODY;
else
return continueNext(it);
}
public int doAfterBody()throws JspTagException
{
return continueNext(it);
}
public int doEndTag()throws JspTagException
{
try
{
if(bodyContent!=null)
bodyContent.writeOut(bodyContent.getEnclosingWriter());
}
catch(java.io.IOException e)
{
}
return EVAL_PAGE;
}
/**
*保護方法,用于把it.next()設置為pagecontext的屬性
*/
protected int continueNext(Iterator it)throws JspTagException
{
if(it.hasNext())
{
pageContext.setAttribute(name,it.next(),PageContext.PAGE_SCOPE);
return EVAL_BODY_TAG;
}
else
{
return SKIP_BODY;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -