📄 myiteratetag.java
字号:
package cn.com.pkusoft.tag;
import java.util.Collection;
import java.util.Iterator;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: pku-soft</p>
* @author weiming
* @version 1.0
*/
public class MyIterateTag
extends BodyTagSupport
{
private String type = null;
private String name = null;
private Collection collection = null;
private Iterator m_iterator = null;
public MyIterateTag()
{
}
public void setCollection(Collection collection)
{
this.collection = collection;
}
public void setType(String type)
{
this.type = type;
}
public void setPageContext(PageContext pc)
{
/**@todo Implement this javax.servlet.jsp.tagext.Tag abstract method*/
this.pageContext = pc;
}
public void doInitBody() throws JspException
{
}
public void setParent(Tag parm1)
{
/**@todo Implement this javax.servlet.jsp.tagext.Tag abstract method*/
}
public Tag getParent()
{
/**@todo Implement this javax.servlet.jsp.tagext.Tag abstract method*/
throw new java.lang.UnsupportedOperationException(
"Method getParent() not yet implemented.");
}
public int doStartTag() throws JspException
{
this.collection = (Collection) pageContext.getSession().getAttribute(this.
name);
if (collection == null)
{
return SKIP_BODY;
}
m_iterator = this.collection.iterator();
if (this.m_iterator.hasNext()) {
this.pageContext.getSession().setAttribute(this.getId(), this.m_iterator.next());
return EVAL_BODY_INCLUDE;
}
else {
return SKIP_BODY;
}
}
public int doAfterBody() throws JspException
{
if (this.m_iterator.hasNext()) {
this.pageContext.getSession().setAttribute(this.getId(), this.m_iterator.next());
return EVAL_BODY_AGAIN;
}
else {
return SKIP_BODY;
}
}
public int doEndTag() throws JspException
{
return super.doEndTag();
}
public void setName(String name)
{
this.name = name;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -