Jstl Fortokens Tag Event - Separate String Inwards Jsp

JSTL forTokens tag is to a greater extent than or less other tag inward meat JSTL library to back upwardly Iteration or looping. It effectively complements, to a greater extent than useful <c:forEach> tag, yesteryear allowing you lot to iterate over comma separated or whatsoever delimited String. You tin purpose this tag to split upwardly string inward JSP in addition to tin operate on them individually. forTokens tag has similar attribute similar forEach JSTL tag except i to a greater extent than attribute called delims, which specifies delimiter. For instance to iterate over colon separated String "abc:cde:fgh:ijk", delims=":". By the way, forTokens tag likewise direct maintain multiple delimiter, which means, you lot tin split a big string into token based upon multiple delimiter e.g. colon(:) in addition to pipe (|), This volition last to a greater extent than clear, when nosotros volition encounter examples of JSTL forTokens tag inward JSP. Rest of attribute e.g. items, var, varStatus, begin, end in addition to step are same, every bit they are inward instance of <c:forEach> tag. For quick review, items specify String which needs to last split-ed inward token in addition to var tally electrical flow String.


JSTL <c:forTokens> Tag Example

JSTL forTokens tag is to a greater extent than or less other tag inward meat JSTL library to back upwardly Iteration or looping JSTL forTokens Tag Example - Split String inward JSPHere is our consummate code instance of using JSTL forTokens tag inward JSP page. In this example, nosotros commencement split upwardly a comma separate String using forTokens tag yesteryear specifying delims=";". When nosotros iterate over tokens, var stand upwardly for electrical flow token. In the minute example, nosotros direct maintain specified multiple delimiter inward delims attribute, delims="|," to split upwardly String yesteryear pipe(|) graphic symbol in addition to 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 inward 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 '|' in addition to ',' 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 '|' in addition to ',' delimiters
USA
New York
UK
London
Japan
Tokyo

That's all on How to purpose JSTL forTokens tag for iterating over comma separated String. Good matter close forTokens tag is that, it non exclusively complements forEach tag, precisely likewise back upwardly multiple delimiters for breaking String into tokens. Quite handy to procedure asking parameters in addition to other text data.

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


Sumber https://javarevisited.blogspot.com/

0 Response to "Jstl Fortokens Tag Event - Separate String Inwards Jsp"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel