资源描述:
《jsp自定义标签iterator遍历list》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、本文来自:www.javaclubcn.comiteartor标签演示List的遍历,对于复杂的对象,则需要更为复杂的处理。1、iteartor标签执行结果如下2、标签类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标签的输出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标签的输出Stringoutstr=(String)it.next();pageContext.getRequest().setAttribute(name,outstr);}returnTagSupport.EVAL_BODY_INCLUDE;}}3、标签配置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