Jstl Fortokens Tag Event - Split Upward String Inwards Jsp
JSTL forTokens tag is unopen to other tag inwards pith 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 piece of job this tag to dissever string inwards JSP in addition to 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 bring multiple delimiter, which means, yous tin split a big string into token based upon multiple delimiter e.g. colon(:) in addition to pipe (|), This volition hold out to a greater extent than clear, when nosotros volition meet examples of JSTL forTokens tag inwards JSP. Rest of attribute e.g. items, var, varStatus, begin, end in addition to step are same, equally they are inwards instance of <c:forEach> tag. For quick review, items specify String which needs to hold out split-ed inwards token in addition to var concur electrical current String.
JSTL <c:forTokens> Tag Example

<%@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 '|' 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 piece of job JSTL forTokens tag for iterating over comma separated String. Good affair nearly forTokens tag is that, it non alone complements forEach tag, precisely likewise back upward 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
0 Response to "Jstl Fortokens Tag Event - Split Upward String Inwards Jsp"
Post a Comment