How to iterate ArrayList<HashMap<String, String>> in a jsp page using JSTL

天大地大妈咪最大 提交于 2019-12-02 05:57:24

There are few things you have to change:

ResultSet are by-default forward only, since your accessing column Stk_prdid multiple time , it does not returns any value.

public ArrayList getAllStockDetails() {
    ...
    Statement stmt = dcon.con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
    ....
    while (rs.next()) {
        HashMap<String, String> stkMap = new HashMap<String, String>();//<-- move here
        stkList.add(stkMap);
        ...
    }
    ....
}

In jsp:

...
<c:forEach var="row" items="${stkList}">
    ...
    <td>${row.prdStk}</td>
    ...
...

For jsp code,

<c:forEach items="${listOfMap}" var="maps">
       <c:forEach items="${maps}" var="mapItem">
             ${mapItem.key} ${mapItem.value}
       </c:forEach>
</c:forEach>

In your case,

<c:forEach items="${stkList}" var="maps">
           <c:forEach items="${maps}" var="mapEntry">
              ${mapEntry['prdStk']}
           </c:forEach>
</c:forEach>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!