2015-03-25 75 views
0

我將此context.setAttribute("isGood", isGood)設置爲一個servlet,以便能夠獲取pageContext.findAttribute("isGood")的JSP文件上的值。JSP:測試是否存在來自pageContext.findAttribute(「」)的變量

有時context.setAttribute("isGood", isGood)無法設置,因此它不存在,我的JSP給我一個錯誤,因爲它不能得到它。

如何測試pageContext.findAttribute("isGood")是否存在於我的JSP中?

謝謝。

回答

1

可以使用條件檢查標記爲:

<c:if test="${pageContext.getAttribute("isGood") != null }"> 

</c:if>