我有一个PersistenceSet,并想检查它是否包含某个变量.
如何检查JSTL是否存在子项目?
但是,当我尝试访问这样的非存在变量时:
<c:if test="${not empty item.subitem}">
<c:out value="${item.subitem}" /><br />
</c:if>
Run Code Online (Sandbox Code Playgroud)
我得到一个PropertyNotFoundException:
在com.company.classname类型上找不到属性'subitem'
很明显,subitem课堂上没有标准的setter/getter
如果您想检查该属性是否适用于该课程,您可以进行以下调整
运用 c:catch
<c:catch var="exception">${item.subitem}</c:catch>
<c:if test="${exception==null}">subitemnot available.</c:if>
Run Code Online (Sandbox Code Playgroud)