我想了解在Hidden features of JSP/Servlet中使用JSTL访问地图时会发生什么情况
在@blausC的答案中,他解释了发生的情况,但是当我尝试使用以下代码时
<c:set var="resultMap" value="validationResults" scope="request"></c:set>
<c:if test="${resultMap['userName'] != null}">
${resultMap['userName'].details}
</c:if>
发生混乱的异常
Caused by: javax.el.PropertyNotFoundException: Property 'userName' not found on type java.lang.String
映射的键应该是字符串,所以该异常是什么,我尝试了上述问题中的示例以及相同的异常,有人可以告诉我我在哪里有误解吗?
编辑:我在servlet中填充地图,并将其发送到jsp
Map<String, ValidationResult> result = new HashMap<String, ValidationResult>();
aValidationResult = new ValidationResult();
check whether the field is valid or not if not fill the map
result.put("userName", aValidationResult);
result.put("group", aValidationResult);
如果地图不为空,则将地图返回到jsp
request.setAttribute("validationResults", result);
当我进行服务器端验证时,地图已填满,
提前感谢。
最佳答案
这是因为String类没有名为getUserName()的方法