JSP: 测试来自 pageContext.findAttribute("") 的变量是否存在
JSP: Test if a variable from pageContext.findAttribute("") exists
我在 servlet 中设置了这个 context.setAttribute("isGood", isGood)
以便能够使用 pageContext.findAttribute("isGood")
.
获取 JSP 文件中的值
有时 context.setAttribute("isGood", isGood)
无法设置,所以它不存在,我的 JSP 给我一个错误,因为它无法获取它。
如何测试我的 JSP 中是否存在 pageContext.findAttribute("isGood")
?
谢谢。
您可以使用条件检查标签作为:
<c:if test="${pageContext.getAttribute("isGood") != null }">
</c:if>
我在 servlet 中设置了这个 context.setAttribute("isGood", isGood)
以便能够使用 pageContext.findAttribute("isGood")
.
有时 context.setAttribute("isGood", isGood)
无法设置,所以它不存在,我的 JSP 给我一个错误,因为它无法获取它。
如何测试我的 JSP 中是否存在 pageContext.findAttribute("isGood")
?
谢谢。
您可以使用条件检查标签作为:
<c:if test="${pageContext.getAttribute("isGood") != null }">
</c:if>