This question already has answers here:
How to loop through a HashMap in JSP?
                            
                                (3个答案)
                            
                    
                2年前关闭。
        

    

这是我的Java代码,用于创建多维哈希图:

HashMap<String, HashMap<String, String>> data = new HashMap<String, HashMap<String, String>>();

for (App app : apps) {
    String randomVar = "";

    data.put(String.valueOf(app.getId()), new HashMap<String, String>());
    data.get(String.valueOf(app.getId())).put("name", app.getName());
    data.get(String.valueOf(app.getId())).put("info", randomVar);
}


这是我的.jsp文件:

<c:forEach items="${data}" var="items">
    <c:forEach items="${items}" var="item">
        <div class="col-md-6">
            <div class="overview">
                <a href="/goto/${items.key}" class="minimal" title="Switch to: ${item.name}">
                    ${item.randomVar}
                    <span>${item.name}</span>
                </a>
            </div>
        </div>
    </c:forEach>
</c:forEach>


不幸的是,我无法使jsp文件中的循环生效。问题出在第二个循环上。我找不到变量。无论尝试什么,都会出现类似Don't know how to iterate over supplied 'items' in <forEach>的错误,或者items.name不存在等等。如何正确循环哈希图?

最佳答案

不应该是items="${items.value}吗?

关于java - JSTL遍历多维哈希图,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45919749/

10-09 03:58