JSP页面中怎么遍历arraylist中的数组数据

从XML中返回的很多层啊。。。╮(╯▽╰)╭

第1个回答  推荐于2018-05-11
有两种方法,第一种的话,用迭代器
ArrayList arrli=new ArrayList();
for(Iterator is=arrli.iterator();is.next())
{
System.out.println(is.next());

}

第二种方法是采用struts标签中的<logic:iterator>进行遍历,这个相对简单些。
其中name属性代表后台传来的list结果集属性名。
<logic:iterate id="rn" name="rl">
<tr>
<th><input type="checkbox" id="e" name="e" value="${rn.id}"></th>
<th><%= index %></th>
<th>${rn.CId}</th>
<th><span style="cursor:hand" onclick="opensreach('linkman.do?os=links&haha=${rn.id}')">${rn.CName}</span></th>
<th>
<html:button property="s1" value="删除" onclick="return chooseaction('shanchu',${rn.id})"/>
<html:button property="s2" value="修改" onclick="choo('myinit',${rn.id})"/>
</th>
</tr>

</logic:iterate>

如有其他疑问可以说下,呵呵。本回答被网友采纳
第2个回答  2013-04-14
java里的简单实现
for(int i=0;i<array.size();i++){
obj=array.get(i);
}
第3个回答  2013-04-14
去看看这个吧 07年就被解决的问题了。。嗷嗷 http://topic.csdn.net/u/20071229/14/70f57a53-be50-43bc-acc6-0f350614712c.html
第4个回答  2013-04-18
 Java代码

  package com.test;

  import java.util.ArrayList;

  import java.util.Iterator;

  import java.util.List;

  public class ArrayListDemo {

  public static void main(String args[]){

  List<String> list = new ArrayList<String>();

  list.add("luojiahui");

  list.add("luojiafeng");

  //方法1

  Iterator it1 = list.iterator();

  while(it1.hasNext()){

  System.out.println(it1.next());

  }

  //方法2 怪异!

  for(Iterator it2 = list.iterator();it2.hasNext();){

  System.out.println(it2.next());

  }

  //方法3

  for(String tmp:list){

  System.out.println(tmp);

  }

  //方法4

  for(int i = 0;i < list.size(); i ++){

  System.out.println(list.get(i));

  }

  }

  }本回答被网友采纳