Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • if-else in jstl

    • 0
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 891
    Comment on it

    In JSTL, the functionality if-else is provided by choose-when-otherwise statement .

    <c:choose> tag is an enclosing tag for <c:when> and <c:otherwise>. And it is also known as mutual exclusion as only a block of code within the condition of mutual exclusion be executed. <c:when> and <c:otherwise> both come under this <c:choose> tag.

    <c:when> tag is equivalent to the case statements of a switch statement. <c:when> statements are considered as more advanced than case statements as switch case statements only compares the variable mentioned in the switch statement w.r.t the constant in case statement while the <c:when> tag evaluates the expressions.

    <c:otherwise> tag is equivalent to the else statements.


    <%@ taglib uri="" prefix="c" %>
             <title> Choose,Otherwise and When (if-else in JSTL)</title>
             <c:if test="${pageContext.request.method=='POST'}">I have
                 <c:out value="${param.enter}" />
                       <c:when test="${param.enter=='0'}">(means no ) notebook.
                      <br />
                    <c:when test="${param.enter=='1'}">notebook.
                     <br />
                      <br />
             <form method="post">Enter a number:
             <input type="text" name="enter" />
             <input type="submit" value="accept" />
             <br />

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: