2013-05-12 97 views
0

我正在嘗試將Java類文件上的ArrayList迭代到jsp文件以顯示錶格格式的輸出。將java中的映射迭代爲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 
+0

[JSTL(http://tomcat.apache.org/taglibs/)是你的朋友 – hd1 2013-05-12 17:20:48

回答

2

您的問題是您將same地圖分配給所有行。你必須分配一個不同的。

abc.add(mpp); 

之後添加

mpp = new HashMap(); 
+0

非常感謝!安傑洛。有效。 – user2357036 2013-05-12 17:43:05