Java Tutorial/JSTL/ForTokens

Материал из Java эксперт
Перейти к: навигация, поиск

JSTL ForTokens

   <source lang="java">

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

 <head>
   <title>Updatable Collections</title>
 </head>
 <body>
<form method="post"> </form>
Parse for Tokens

Enter a sentence:
<input width="20" maxwidth="20" name="text" size="50" />
 

<input type="submit" name="parse" value="Parse" />

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

</html></source>





Use JSTL ForTokens to split string

   <source lang="java">

<%@ taglib prefix="c" uri="http://java.sun.ru/jstl/core" %> <c:set var="names" value="A:B;C|D" scope="page" /> <html>

 <head>
   <title>forTokens action</title>
 </head>
 <body>
   <c:forTokens items="${pageScope.names}"
                delims=":;|"
                var="currentName"
                varStatus="status"
     >
     Family member #<c:out value="${status.count}" /> is
       <c:out value="${currentName}" /> 
</c:forTokens> </body>

</html></source>