JSTL Iteration over tokens : Collections « JSTL « Java






JSTL Iteration over tokens

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
  <head>
    <title>Updatable Collections</title>
  </head>

  <body>
    <table border="0">
      <form method="post">
        <tr bgcolor="blue">
          <td>
            <p align="center">
              <b>
                <font color="#FFFFFF">Parse for Tokens</font>
              </b>
            </p>
          </td>
        </tr>

        <tr>
          <td valign="top">
            <p align="left">Enter a sentence:
            <br />

            <input width="20" maxwidth="20" name="text"
            size="50" />

            <br />

            &#160;</p>
          </td>
        </tr>

        <tr>
          <td valign="top">
            <p align="center">
              <input type="submit" name="parse" value="Parse" />
            </p>
          </td>
        </tr>
      </form>
    </table>

    <c:if test="${pageContext.request.method=='POST'}">
      <table border="1">
        <c:set var="i" value="1" />
        <c:forTokens items="${param.text}" var="word"
        delims=" ,.?!">
          <c:set var="i" value="${i}" />

          <tr>
            <td>
              <b>Word 
              <c:out value="${i}" />
              </b>
            </td>

            <td>
              <c:out value="${word}" />
            </td>
          </tr>
        </c:forTokens>
      </table>
    </c:if>
  </body>
</html>



           
       








JSTL-Iteration-over-tokens.zip( 852 k)

Related examples in the same category

1.JSTL Modify a collection
2.String Collection Examples