Skip to content
Fix Code Error

Evaluate empty or null JSTL c tags

March 13, 2021 by Code Error
Posted By: Anonymous

Solution

How can I validate if a String is null or empty using the c tags of JSTL?

You can use the empty keyword in a <c:if> for this:

<c:if test="${empty var1}">
    var1 is empty or null.
</c:if>
<c:if test="${not empty var1}">
    var1 is NOT empty or null.
</c:if>

Or the <c:choose>:

<c:choose>
    <c:when test="${empty var1}">
        var1 is empty or null.
    </c:when>
    <c:otherwise>
        var1 is NOT empty or null.
    </c:otherwise>
</c:choose>

Or if you don’t need to conditionally render a bunch of tags and thus you could only check it inside a tag attribute, then you can use the EL conditional operator ${condition? valueIfTrue : valueIfFalse}:

<c:out value="${empty var1 ? 'var1 is empty or null' : 'var1 is NOT empty or null'}" />

To learn more about those ${} things (the Expression Language, which is a separate subject from JSTL), check here.

See also:

  • How does EL empty operator work in JSF?
Answered By: Anonymous

Related Articles

  • How to install JSTL? The absolute uri:…
  • Reference - What does this regex mean?
  • Can not find the tag library descriptor for…
  • Search match multiple values in single field in…
  • How can I avoid Java code in JSP files, using JSP 2?
  • Sun JSTL taglib declaration fails with "Can not find…
  • Vue custom directive uses the updated Dom (or $el)
  • The absolute uri: http://java.sun.com/jsp/jstl/core…
  • How to properly do JSON API GET requests and assign…
  • “tag already exists in the remote" error after…
  • What is git tag, How to create tags & How to…
  • No Spring WebApplicationInitializer types detected…
  • Can not find the tag library descriptor for…
  • commandButton/commandLink/ajax action/listener…
  • loop and eliminate unwanted lines with beautiful soup
  • show all tags in git log
  • How to use Servlets and Ajax?
  • How would I access variables from one class to another?
  • JSP tricks to make templating easier?
  • How to make Lodash orderBy to sort only the records…
  • Use vee-validate to validate select list with radio…
  • Attaching textarea by v-model to computed with other…
  • How to set HTML5 required attribute in Javascript?
  • backbone collection add does not trigger model validate
  • Smart way to truncate long strings
  • What's the difference between including files with…
  • What is your most productive shortcut with Vim?
  • python 3.2 UnicodeEncodeError: 'charmap' codec can't…
  • Understanding PrimeFaces process/update and JSF…
  • Why after set mapping, index return nothing?
  • how to display validation error message out from the…
  • How to resolve : Can not find the tag library…
  • Identifying and solving…
  • How to handle Vue 2 memory usage for large data (~50…
  • What is it about Vue that enables developers to use…
  • How to resolve "Could not find schema information…
  • How to handle initializing and rendering subviews in…
  • Iterating through a List Object in JSP
  • Backbone: validating attributes one by one
  • How can I wrap all BeautifulSoup existing…
  • Composition of typescript generics
  • Does "git fetch --tags" include "git fetch"?
  • Alpine js get "tag input" as array
  • Unable to run Robolectric and Espresso with a…
  • Logging best practices
  • how to validate both input fields when one updates
  • Use of Jquery on scroll event
  • Typescript in vue - Property 'validate' does not…
  • Using Event Aggregator to load a view with different…
  • What is a NullReferenceException, and how do I fix it?
  • Do you (really) write exception safe code?
  • How to make Nuxt global object?
  • coercing to Unicode: need string or buffer, NoneType…
  • What is an optional value in Swift?
  • Create a tag in a GitHub repository
  • What does "Fatal error: Unexpectedly found nil while…
  • Correct syntax to compare values in JSTL
  • Validating a non-existent field error in console
  • Neither BindingResult nor plain target object for…
  • What does do?
  • Backbone.js newbie - cannot get model error event to fire
  • What is an IndexOutOfRangeException /…
  • How to enforce required paper-radio-group in Polymer?
  • Check a collection size with JSTL
  • How to list all Git tags?
  • Push git commits & tags simultaneously
  • Getting related news by tags in Gatsby and GraphQL
  • TypeError: Object(...) is not a function in Vue
  • Uncaught Error: [vee-validate] No such validator…
  • How to dispatch a Redux action with a timeout?
  • What are the currently supported CSS selectors…
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • How do I display a MySQL error in PHP for a long…
  • Vue js vee validate password confirmation always false
  • Split (explode) pandas dataframe string entry to…
  • How does PHP 'foreach' actually work?
  • Elastic search filter not working for multi value json
  • enum to string in modern C++11 / C++14 / C++17 and…
  • Why does C++ code for testing the Collatz conjecture…
  • Fastest way to iterate over all the chars in a String
  • Creating an dynamic array, but getting segmentation…
  • Usage of __slots__?
  • How to find out client ID of component for ajax…
  • Backbone.js Backbone.wrapError function
  • how to toggle class for multiple elements in vue js
  • What is the worst programming language you ever worked with?
  • ember-data: Updating a record with a many-to-many…
  • java.lang.ClassNotFoundException:…
  • Filter models by related model (hasMany)
  • How to separate opening and closing tag by…
  • What's the difference between eval, exec, and compile?
  • Apply attribute-sets on existing elements
  • accessing another models data in ember.js
  • Backbone JS add extended model to a collection of…
  • How to download and save an image in Android
  • Conditional logic in AngularJS template
  • How to list all tags along with the full message in git?
  • Format Column Data before passing to Vue Good-Table
  • Adding tags to azure VMs via CSV
  • Jquery Validate custom error message location

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

Array to String PHP?

Next Post:

How to convert a char array back to a string?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error