JSTL循环遍历多维hashmap

时间:2017-08-28 13:03:18

标签: java loops jsp hashmap jstl

这是我创建多维hashmap的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不存在等错误,等等。如何正确循环hashmap?

1 个答案:

答案 0 :(得分:1)

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