JSTL:检查字符串是否为空
我正在尝试在JSTL中测试会话属性是否为空。但是,该属性为空,JSTL 将其视为非空属性。
这是我试图用JSTL替换的硬代码。此代码工作正常:
<% if (request.getAttribute("error") != null) { %>
<div class="alert alert-danger">
<strong>Oh snap, something's wrong, maybe the following error could help you out?<br /></strong>
<%= request.getAttribute("error")%>
</div>
<% } %>
这就是我用JSTL替换它的方式。选中后,error 属性不为空,但为空。
<c:if test="${not empty sessionScope.error}">
<div class="alert alert-danger">
<strong>Oh snap, something's wrong, maybe the following error could help you out?<br /></strong>
<c:out value="${sessionScope.error}" />
</div>
</c:if>