JSTL Check String Empty OR NULL
JSTL Check String Empty OR NULL explains about how to evaluate a string whether it is empty or null inside JSP
Consider a JSP Page where you need to check a string and process accordingly, in this case you can follow this example.
You can check a string whether it is empty or not using "empty" keyword in JSTL
<c:if test="${empty str1}"> </c:if>
Above code will check value of str1 is empty or null
Required Libraries
Project Structure
JSTL Check String Empty OR NULL
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%> <html> <head> <title>Evaluate String Empty OR NULL JSTL</title> </head> <body> <% // you can also set the values into using c:set request.setAttribute("str1", null); request.setAttribute("str2", "hello"); %> <c:if test="${empty str1}"> str1 is empty or null. </c:if> <br/> <c:if test="${not empty str2}"> str2 is not empty or null. </c:if> </body> </html>
Output
str1 is empty or null.str2 is not empty or null.
1 Responses to "JSTL Check String Empty OR NULL"