如何拆分/分离ArrayList中的数据并存储到HTML表?

时间:2013-07-17 03:56:24

标签: java html jsp hashmap

我正在尝试将hashMap数据存储到ArrayList中。问题是当我将数组列表中的内容显示到html表时,它会在单个单元格中显示整个列表。我不知道在哪里可以开始解决问题,我是否在存储时分离/拆分数据,或者在需要在html表中显示时将它们分开/拆分。

  

相关代码

HashMap hashdata = new HashMap();
List display = hashdata.displayhtml();
  

displayhtml()

Map<Integer,List<Integer>> hashdata = new hashdata<Integer,List<Integer>>();
List<Object> listOfObjects = new ArrayList<Object>();

.....
......
.......
for (int i = 0; i < db.getNumberOfRows(); i++) {

        hashdata.put(i,db.getDataAtRow(i));            
    }
    //return tranFIT;
    for (int i = 0; i < db.getNumberOfRows(); i++) {

        listOfObjects.add(hashdata.get(i) + "\n");
    }
    return listOfObjects;
  

html table

<table>
<tr>
<%for(int x.....){
     for(int y.....) {%>
    <td>.....<%=display%>.....</td>
   <%}
}%>
</tr>

  

输出

enter image description here

请提供一些提示和建议。

1 个答案:

答案 0 :(得分:0)

首先,java中的所有内容都是Object。首先,您需要创建一个对象。让我们将其称为PersonInfo,并使用您拥有的数据构造此对象。

public class PersonInfo{
    private String name;
    private int age;
    private String address;
    private int telephone; 
    // add setter/getter below
}

假设您有PersonInfo personInfo 在显示时,您可以使用personInfo.getName()等。 不确定是否要使用List<PersonInfo> list = new ArrayList<PersonInfo>()而不是Map。