Use Choose/When/Otherwise to Check Form CheckBox Data : Form CheckBox « JSTL « Java Tutorial






index.jsp

<form method="post" action="checkbox.jsp">
  <P>Please check adjectives you would
  use to describe this web site's
  customer service:</p>

  <P>Atrocious
  <input type="checkbox" name="feedback" value="atrocious"/></p>

  <P>Loathsome
  <input type="checkbox" name="feedback" value="loathsome"/></p>

  <P>Flagitious
  <input type="checkbox" name="feedback" value="flagitious"/></p>

  <P>Satisfactory
  <input type="checkbox" name="feedback" value="satisfactory"/></p>

  <P><input type="submit" value="Submit" /></p>
</form>

checkbox.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

<c:choose>
 <c:when test="${not empty paramValues.feedback}">
  You described our customer service as
  <ul>
  <c:forEach items="${paramValues.feedback}" var="adj">
    <c:choose>
      <c:when test="${adj == 'satisfactory'}">
         <font size="+2">
      </c:when>
      <c:otherwise>
         <font size="-2">
      </c:otherwise>
    </c:choose>
    <li><c:out value="${adj}"/></li>
    </font>
  </c:forEach>
 </c:when>
 <c:otherwise>
  You didn't choose any feedback checkboxes.
 </c:otherwise>
</c:choose>
  Download:  JSTLUseChooseWhenOtherwiseToCheckFormCheckBoxData.zip( 940 k)








24.14.Form CheckBox
24.14.1.Use ForEach to Check Form CheckBox Data
24.14.2.Use Choose/When/Otherwise to Check Form CheckBox Data
24.14.3.Use Bean to Deal with CheckBox