Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Checking variable existance using JSTL
08-23-2008, 11:34 PM
Post: #1
Checking variable existance using JSTL
How can I check a variable's existance using JSTL? I am expecting an attribute in my session and if that attribute exist I need to display a block of code. How can I do that?
Find all posts by this user
Quote this message in a reply
08-24-2008, 12:27 AM
Post: #2
RE: Checking variable existance using JSTL
You can use <c:if> for that purpose.

Code:
<c:if test='${not empty variableName}'>
    <c:out value="${variable}" />
</c:if>

Where variable is your variable name. If you have a variable named var in your session and if you want to check whether that variable existence or not use the following code.

Code:
<c:if test='${not empty sessionScope.var}'>
    <c:out value="${variable}" />
</c:if>
Visit this user's website Find all posts by this user
Quote this message in a reply
08-24-2008, 12:33 AM
Post: #3
RE: Checking variable existance using JSTL
I need something like a if else . If the variable exist display some content else some other content. Please give me the code for that.
Find all posts by this user
Quote this message in a reply
08-24-2008, 12:34 AM
Post: #4
RE: Checking variable existance using JSTL
Here you go.

Code:
<c:choose>
    <c:when test="${not empty sessionScope.var}">
        Variable exist.
    </c:when>
    <c:otherwise>
        Variable does not exist.
    </c:otherwise>
</c:choose>
Visit this user's website Find all posts by this user
Quote this message in a reply
08-24-2008, 12:39 AM (This post was last modified: 08-24-2008 12:40 AM by reena.)
Post: #5
RE: Checking variable existance using JSTL
Thank you.
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: