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

Jstl

Jstl Problem Overview


E.g.

<c:if test="${post}">
	<h3>${post.title}</h3>	
</c:if>

Jstl Solutions


Solution 1 - Jstl

Use the empty keyword

<c:if test="${not empty post}">
   <h3>${post.title}</h3>	
</c:if>

Solution 2 - Jstl

You can also use '!' instead 'not' :

<c:if test="${!empty post}">
    <h3>${post.title}</h3>
</c:if>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSergio del AmoView Question on Stackoverflow
Solution 1 - JstlkrosenvoldView Answer on Stackoverflow
Solution 2 - Jstlhejiaming007View Answer on Stackoverflow