?? myiteratortag.java
字號:
package mytag;import javax.servlet.jsp.*;import javax.servlet.jsp.tagext.*;import java.util.Hashtable;import java.io.Writer;import java.io.IOException;import java.util.List;/** * @author yeeku.H.lee kongyeeku@163.com * @version 1.0 * <br>Copyright (C), 2005-2008, yeeku.H.Lee * <br>This program is protected by copyright laws. * <br>Program Name: * <br>Date: */public class MyIteratorTag extends BodyTagSupport{ private String bean; private String item; private String scope; private int i = 0; private int size; private List<String> itemList = null; public void setBean (String s) { bean = s; } public void setScope (String s) { scope = s; } public String getBean () { return bean; } public void setItem (String s) { item = s; } public String getItem () { return item; } public int doStartTag() throws JspTagException { if (scope.equals("page")) { itemList = (List<String>)pageContext.getAttribute(bean); } else if(scope.equals("request")) { itemList = (List<String>)pageContext.getAttribute(bean , PageContext.REQUEST_SCOPE); } else if(scope.equals("session")) { itemList = (List<String>)pageContext.getAttribute(bean , PageContext.SESSION_SCOPE); } else if(scope.equals("application")) { itemList = (List<String>)pageContext.getAttribute(bean , PageContext.APPLICATION_SCOPE); } if (itemList == null) { System.out.println("集合為空"); return SKIP_BODY; } //測試用的 System.out.println(itemList); size = itemList.size(); pageContext.setAttribute(item , itemList.get(i)); return EVAL_BODY_BUFFERED; } public int doAfterBody() throws JspException { System.out.println("標簽體結束"); i++ ; if (i >= size) { i = 0; return SKIP_BODY; } pageContext.setAttribute(item , itemList.get(i)); return EVAL_BODY_AGAIN; } public int doEndTag() throws JspTagException { if (itemList == null ) { return EVAL_PAGE; } else { try { bodyContent.writeOut(pageContext.getOut()); } catch (IOException ex) { throw new JspTagException("錯誤"); } return EVAL_PAGE; } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -