0

我正在尝试将 java 类文件上的 arraylist 迭代到 jsp 文件以以表格式显示输出。

JSP 文件:

<jsp:useBean id="mybean3" class="org.mypackage.process" scope="session" >  
  <jsp:setProperty name="mybean3" property="type" value="CARRIER DATA FILES" />
</jsp:useBean>

<table><tr><th>Header1</th> <th>Header2</th></tr>
<c:forEach items="${mybean3.values}" var="element3">
<tr>   <td><c:out value="${element3.DISTTT}" /></td>
    <td><c:out value="${element3.MESS}" /></td></tr>
  </c:forEach>

Java类文件:

public void setType(String typecol) {
  mpp= new HashMap();
  abc = new ArrayList();
  this.typecol = typecol;
  for (int j=0;j<=5;j++){
    mpp.put("DISTTT",j);
    mpp.put("MESS",j);
    abc.add(mpp);   
  }
}

public ArrayList getValues(){
  Object ob;
  this.Values = abc;
  return Values;
}

期望 O/P:

Header1 Header2
1          1 
2          2 
3          3
4          4
5          5

当前 O/P:

Header1 Header2
5         5
5         5
5         5
5         5
5         5
4

1 回答 1

2

您的问题是您将same地图分配给所有行。你必须分配一个不同的。

abc.add(mpp);

添加

mpp = new HashMap();
于 2013-05-12T17:23:36.290 回答