Java – JSTL: check whether the string is empty
•
Java
See the English answer > evaluate empty or null JSTL C tags8
This is hard coding I'm trying to replace with JSTL This code works correctly:
<% 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>
<% } %>
This is how I replace it with JSTL When selected, the error attribute is not empty, but it is empty
<c:if test="${not empty sessionScope.error}">
<div class="alert alert-danger">
<strong>Oh snap,maybe the following error Could help you out?<br /></strong>
<c:out value="${sessionScope.error}" />
</div>
</c:if>
Solution
Add the JSTL library and declare the core taglib:
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
JSTL is equivalent to
<% if (request.getAttribute("error") != null) { %>
yes
<c:if test="${not empty error}">
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
