Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i check if an attribute is set (not null and not an empty string) with jstl? [duplicate]

Tags:

jstl

E.g.

<c:if test="${post}">     <h3>${post.title}</h3>   </c:if> 
like image 225
Sergio del Amo Avatar asked May 15 '09 09:05

Sergio del Amo


People also ask

How check list is empty or not in JSTL?

The first way is to use the JSTL tag and empty operator to check if an ArrayList is empty and the second way is to use the JSTL function, fn: length() instead of the empty operator as shown in our example.

IS NULL value same as empty string?

The Java programming language distinguishes between null and empty strings. An empty string is a string instance of zero length, whereas a null string has no value at all. An empty string is represented as "" . It is a character sequence of zero characters.

How check string is null or not in JSP?

To check if a string is null or empty in Java, use the == operator.

Is empty in JSTL?

Summarized: empty doesn't work on Set when using the ancient JSTL 1.0. You'd need to upgrade to JSTL 1.1 (which is from 2003 already).


1 Answers

Use the empty keyword

<c:if test="${not empty post}">    <h3>${post.title}</h3>    </c:if> 
like image 162
krosenvold Avatar answered Sep 29 '22 06:09

krosenvold