我有一个存储在会话中的哈希图。hashMap 是映射的映射。
HashMapStoredInSession ={"290" = {text="abc", response="someText"}, "276"={text="xyz", response="random"}};
我不想使用脚本。但是我被一个脚本卡住了,似乎无法让它工作。任何我出错的建议都会很棒。以下 SCRIPTLET + JSTL 的组合有效
小脚本:
<%
Map hMap= (Map)request.getSession().getAttribute("HashMapStoredInSession");
pageContext.setAttribute("mapofMaps", hMap);
%>
JSTL 代码:
<c:if test="${param.ID != 'null' && not empty param.ID}">
<c:set var="someID" value="${param.ID}" scope="session"/>
</c:if>
<c:forEach items="${mapofMaps}" var="outerMap">
<c:if test="${outerMap.key == someID}"> // this is the line where exception is thrown when the above scriptlet code is replaced with JSTL below
<c:forEach items="${outerMap.value}" var="innerMap">
<c:if test="${innerMap.key == 'param1'}">
<c:set var="response1" value="${innerMap.value}"/>
</c:if>
<c:if test="${innerMap.key == 'param2'}">
<c:set var="response2" value="${innerMap.value}"/>
</c:if>
</c:forEach>
</c:if>
</c:forEach>
现在,如果我尝试用以下替换 scriptlet 代码(JSTL 代码没有变化)
<c:set var="mapofMaps" value ='<c:out value ="<%=request.getSession().getAttribute("HashMapStoredInSession")%>"/>'/>
我收到以下错误
An error occurred while evaluating custom action attribute "test" with value "${outerMap.key == someID}":
Unable to find a value for "key" in object of class "java.lang.String" using operator "." (null)