tumblr counter

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

You need to download

  1. Tomcat 7
  2. JSTL 1.2

Following jar must be in classpath

  1. jstl-1.2.jar

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.

 




JSTL Check String Empty OR NULL Evaluate Empty OR NULL JSTL C Tag Check NULL In JSTL

You might also like following tutorials :

Java Tutorial Apache CXF Tutorial Hibernate Tutorial Spring Tutorial Struts Tutorial
0 Comments on "JSTL Check String Empty OR NULL"