Jstl Fortokens Tag Illustration - Dissever String Inwards Jsp

JSTL forTokens tag is but about other tag inwards gist JSTL library to back upward Iteration or looping. It effectively complements, to a greater extent than useful <c:forEach> tag, yesteryear allowing yous to iterate over comma separated or whatever delimited String. You tin run this tag to dissever string inwards JSP together with tin operate on them individually. forTokens tag has similar attribute similar forEach JSTL tag except 1 to a greater extent than attribute called delims, which specifies delimiter. For representative to iterate over colon separated String "abc:cde:fgh:ijk", delims=":". By the way, forTokens tag likewise convey multiple delimiter, which means, yous tin split a big string into token based upon multiple delimiter e.g. colon(:) together with pipe (|), This volition live on to a greater extent than clear, when nosotros volition encounter examples of JSTL forTokens tag inwards JSP. Rest of attribute e.g. items, var, varStatus, begin, end together with step are same, equally they are inwards instance of <c:forEach> tag. For quick review, items specify String which needs to live on split-ed inwards token together with var concur electrical current String.


JSTL <c:forTokens> Tag Example

JSTL forTokens tag is but about other tag inwards gist JSTL library to back upward Iteration or looping JSTL forTokens Tag Example - Split String inwards JSPHere is our consummate code representative of using JSTL forTokens tag inwards JSP page. In this example, nosotros commencement dissever a comma separate String using forTokens tag yesteryear specifying delims=";". When nosotros iterate over tokens, var stand upward for electrical current token. In the instant example, nosotros conduct maintain specified multiple delimiter inwards delims attribute, delims="|," to dissever String yesteryear pipe(|) graphic symbol together with comma (,) character.


<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title> JSTL forTokens tag Example - Iterate over comma separated String inwards JSP</title>
    </head>

    <body>

        <h3> forTokens Tag Example</h3>

        <h4>String amongst comma ',' delimiter</h4>

        <c:forTokens var="token" items="Java, J2EE, JSTL, JSP, Servlet"
                     delims=",">
            <c:out value="${token}"/> </br>
        </c:forTokens>

        <h4>Iterating over String amongst '|' together with ',' delimiters</h4>

        <c:forTokens var="token" items="USA,New York,UK|London,Japan|Tokyo"
                     delims="|,">
            <c:out value="${token}"/> </br>
        </c:forTokens>
    </body>
</html>

Output:
forTokens Tag Example
String amongst comma ',' delimiter
Java
J2EE
JSTL
JSP
Servlet

Iterating over String amongst '|' together with ',' delimiters
USA
New York
UK
London
Japan
Tokyo

That's all on How to run JSTL forTokens tag for iterating over comma separated String. Good matter well-nigh forTokens tag is that, it non solely complements forEach tag, but likewise back upward multiple delimiters for breaking String into tokens. Quite handy to procedure asking parameters together with other text data.

Further Learning
Spring Framework 5: Beginner to Guru
Java Web Fundamentals By Kevin Jones
JSP, Servlets together with JDBC for Beginners: Build a Database App

Belum ada Komentar untuk "Jstl Fortokens Tag Illustration - Dissever String Inwards Jsp"

Posting Komentar

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel