我有一个 PersistenceSet,想检查它是否包含某个变量。
如何在 JSTL 中检查子项是否存在?
但是当我尝试像这样访问一个不存在的变量时:
<c:if test="${not empty item.subitem}">
<c:out value="${item.subitem}" /><br />
</c:if>
我得到一个 PropertyNotFoundException:
Property 'subitem' not found on type com.company.classname
最佳答案
很明显,类中的subitem
没有标准的setter/getter
如果您想检查该属性是否可用于该类,您可以进行以下调整
使用 c:catch
<c:catch var="exception">${item.subitem}</c:catch>
<c:if test="${exception==null}">subitemnot available.</c:if>
关于java - 检查JSTL中是否存在变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7023375/