【发布时间】:2020-10-03 18:25:26
【问题描述】:
我正在研究 jsp,并面临一些与语法相关的问题(这就是我认为的问题)。所以,我的jsp代码有一个map,它通过ModelAndView作为Map推送到jsp。在jsp中,我想将map.key与字符串进行比较,如果相等,则显示,否则跳过该map.key并继续其他人。
代码sn-p:
<c:forEach items = "${maker_model.kycPoiRejectionCodeMap}" var = "reasonEntry" >
<c:if test= "${reasonEntry.key eq 'stringToCompare'}">
//Show reasonEntry.value this if reasonEntry.key is 'stringToCompare'
</c:if>
<c:otherwise>
//else this
</c:otherwise>
</c:forEach>
<c:if test= "${reasonEntry.key eq 'stringToCompare'}"> 不工作。我试过<c:if test= "${reasonEntry.key == 'stringToCompare'}">,但也没有用。
我已经解决了这个问题:compare-map-keys-with-some-element-and-based-on-the-result-show-its-values 和 hash-map-key-check-in-jstl 但在解决方案中他们已经删除了比较本身,在第二个中,我按照建议做的事情。我还搜索了其他问题,但没有找到任何线索。
可能有用:可能有用:reasonEntry.key 中的值是从 enum::name(Enum.java 的 name() 方法)中提取的。
谁能告诉我如何解决这个问题?
【问题讨论】:
-
你确定
reasonEntry.key是String的类型吗? -
你试过
<c:if test=${hmap.containsKey('stringToCompare')}>吗?
标签: java jsp jstl string-comparison jsp-tags