Add/Remove Form Select Option Item : Form Select « JSTL « Java Tutorial

<%@ taglib uri="" prefix="c" %>
<c:if test="${pageContext.request.method=='POST'}">
    <c:when test="${param.add!=null}">
      <c:if test="${list!=null}">
        <c:set var="list" value="${list}," scope="session" />

      <c:set var="list" value="${list}${param.item}"
      scope="session" />

    <c:when test="${param.remove!=null}">
      <c:set var="list2" value="" />

      <c:forEach var="item" items="${list}">
        <c:if test="${item!=param.item}">
          <c:if test="${list2!=''}">
            <c:set var="list2" value="${list2}," />

          <c:set var="list2" value="${list2}${item}" />

      <c:set var="list" value="${list2}" scope="session" />

      <c:remove var="list2" />

    <title>Updatable Collections</title>

    <table border="0">
      <form method="post">
        <tr bgcolor="blue">
          <td colspan="2">
            <font color="white">Updatable Collections</font>

          <td valign="top">
            <select NAME="choice" SIZE="5" width="20">
              <c:forEach var="item" items="${list}">
                  <c:out value="${item}" />

          <td valign="top">Enter a item to add or remove.
          <br />

          <input width="20" maxwidth="20" name="item" size="20" />

          <br />

          <input type="submit" name="add" value="Add" />

          <input type="submit" name="remove" value="Remove" />
  Download: 1,225 k)

24.16.Form Select
24.16.1.JSTL Form Select and CheckBox Group
24.16.2.Use JSTL to Check Selected Value From Form Select Option
24.16.3.Add/Remove Form Select Option Item