Iterating through 2D ArrayList and displaying it on JSP page

牧云@^-^@ 提交于 2019-12-08 08:19:50

问题


I tried looking this up but didn't find anything that answered my question.

So what I've got is something that looks like this:

private List<List<String>> data = new ArrayList<List<String>>();

This has a getter / setter and is being populated by this line:

String[] name = new String[columnCount];
for (int i = 0; i < columnCount; i++ ) {
  name[i] = rsmd.getColumnName(i+1);
  Array tempArray = rs.getArray(name[i]);
  data.add((List<String>) tempArray);
}

In my jsp I know I need something like this:

<s:iterator value="data">
        <th><s:property/></th>
    </s:iterator>
</tr>

I'm stuck though on how to iterate a 2D array and if it matters that it's an ArrayList.


回答1:


Array is a SQL type, you need to get a Java array to use with the iteratator tag.

data.add((List<String>) Arrays.asList(tempArray.getArray()));

On JSP you should use two nested iterator tags.

<s:iterator var="row" value="data">
  <tr>
  <s:iterator value="#row">
    <td><s:property/></td>
  </s:iterator>
  </tr>
</s:iterator>


来源:https://stackoverflow.com/questions/29759995/iterating-through-2d-arraylist-and-displaying-it-on-jsp-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!