If you need to make a multi-way choice while putting together a JSP the way to do it is with the c:choose JTSL tag. The c:choose tag provides the equivalent of an if-else construct but is a lot more verbose. The basic c:choose tag usage looks like this:

<?xml version="1.0" encoding="UTF-8" ?>
<jsp:root xmlns:jsp=
"http://java.sun.com/JSP/Page"
 
xmlns:c="http://java.sun.com/jsp/jstl/core"
 
version="2.0">
<html xmlns=
"http://www.w3.org/1999/xhtml">
  <head>
    <title>c:forEach Example</title>
  </head>
  <body>
    <c:choose>
          <c:when test="$
{bean.value}">
        <p>True</p>
      </c:when>
      <c:otherwise>
        <p>False</p>
      </c:otherwise>
      </c:choose>
  </body>
</html>

There is no limit to the number of c:when clauses that you can include inside a c:choose which mimic else if in regular Java. Having said that it is generally considered good practice to minimize the number of ranch points in the JSP page as they make the page far more complex and they are much slower to process than branch points in code.

In the above example a simple boolean bean property is used to make the choice. There is, however, nothing to stop the use of JSP Expression Language (EL) in the test and therefore production of a very complex test. As with the comment on the number of branch points above it is generally a good idea to keep the complexity of page side test a low as possible.

A more useful example of c:choose in action can be seen below. By using c:choose one can apply banding to a tables rows which makes it easier to view. To apply a different colour to alternate rows a construct such as that shown below could be used.

<?xml version="1.0" encoding="UTF-8" ?>
<jsp:root xmlns:jsp=
"http://java.sun.com/JSP/Page"
 
xmlns:c="http://java.sun.com/jsp/jstl/core"
 
version="2.0">
<html xmlns=
"http://www.w3.org/1999/xhtml">
  <head>
    <title>c:forEach Example</title>
  </head>
  <body>
    <table>
      <c:forEach var=
"person" items="${people.people}" varStatus="rowCounter">
        <c:choose>
          <c:when test=
"${rowCounter.count % 2 == 0}">
            <c:set var=
"rowStyle" scope="page" value="odd"/>
          </c:when>
          <c:otherwise>
            <c:set var=
"rowStyle" scope="page" value="even"/>
          </c:otherwise>
        </c:choose>
        <tr
class="${rowStyle}">
          <td>$
{person.name}</td>
          <td>$
{person.age}</td>
          <td>$
{person.height}</td>
        </tr>
      </c:forEach>
    </table>
  </body>
</html>