I was wondering if we could check for all undefined and null variables in JSP using its built-in functions?
I know I can build a function to do that, but I need a lazy solution.
<c:if test="${name == null}">variable name is undefined</c:if>
For testing you can define and undefine a variable using:
<c:set var="name" value="Petra"/>
<c:set var="name" value="${null}"/>
To state you are using the core JSTL tags add this to the top of the page:
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
There are No built-in functions to check this in a JSP, so I guess you would have to make one, which I think should be a fairly simple task if you take the bookish meaning of null.
If not bookish then null is sort of an overloaded term, it could mean any of the following in general usage:
null String, which could throw NullPointerException."", empty string which might be called null."null"null array. :-)null objects ...So you can build a method to include these or other cases you can think of for null-check or just the basic-primitive-unembellished null-check.
In Java I suppose there is no such thing as an undefined variables, since it is a statically typed language and compiler would catch any of these so called undefined errors :-)
In PHP (since I think you took this function from there) you have these things because it is a scripting language and is not a statically typed language like Java.
Hope this helps.