資源描述:
《jsp自定義標(biāo)簽iterator遍歷list》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、本文來自:www.javaclubcn.comiteartor標(biāo)簽演示List的遍歷,對(duì)于復(fù)雜的對(duì)象,則需要更為復(fù)雜的處理。1、iteartor標(biāo)簽執(zhí)行結(jié)果如下2、標(biāo)簽類IteratorTag.javapackagecom.javaclubcn.tag;importjava.util.Iterator;importjava.util.List;importjavax.servlet.jsp.JspException;importjavax.servlet.jsp.tagext.Ta
2、gSupport;publicclassIteratorTagextendsTagSupport{privateStringname;privateStringvalue;privateIteratorit;publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}istheTibetanPlateaupoly.Centercityonlyapopulationofoveronemillion.X
3、iningislocatedinthe"Tangfangudao"andtheancient"SilkRoad"road,istheLoessPlateauandtheTibetanPlateau,agriculturalandpastoralareasand,inconjunctionwiththeMinistryofcultureandIslamicculturepublicStringgetValue(){returnvalue;}publicvoidsetValue(Stringvalue
4、){this.value=value;}@OverridepublicintdoAfterBody()throwsJspException{//TODOAuto-generatedmethodstubif(it.hasNext()){//取出String,并放置到request中,用于out標(biāo)簽的輸出Stringoutstr=(String)it.next();pageContext.getRequest().setAttribute(name,outstr);returnTagSupport.E
5、VAL_BODY_AGAIN;}else{returnTagSupport.EVAL_PAGE;}}@OverridepublicintdoStartTag()throwsJspException{//TODOAuto-generatedmethodstub//取出listListlist=(List)pageContext.findAttribute(value);it=list.iterator();//先要取出一次if(it.hasNext()){//取出String,并放置到request
6、中,用于out標(biāo)簽的輸出Stringoutstr=(String)it.next();pageContext.getRequest().setAttribute(name,outstr);}returnTagSupport.EVAL_BODY_INCLUDE;}}3、標(biāo)簽配置tld文件javaclubcn-tag.tld,放到WEB-INF文件夾下。
7、s,Inc.//DTDJSPTagLibraryistheTibetanPlateaupoly.Centercityonlyapopulationofoveronemillion.Xiningislocatedinthe"Tangfangudao"andtheancient"SilkRoad"road,istheLoessPlateauandtheTibetanPlateau,agriculturalandpastoralareasand,inconjunctionwiththeMinistryo
8、fcultureandIslamicculture1.2//EN""http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">1.01.2mytag