JSTL Core Tags

JSTL Core Tags:
JSTL – JavaServer Pages Standard Tag Library,
Component of the Java Web application which extends the JSP specification by adding a tag library of JSP tags.

JSTL helps us to avoid using java codes within JSP. JSTL tags can be classified into core, formatting, sql, xml and jstl function tags.

In this article we are going to see JSTL Core Tags. We are going to see some examples of JSTL core tags.

<c:set> – helps to set a value to variable
<c:out> – Used to print the value
<c:if> – If loop
<c:choose> – Similar to If else
<c:when> – used within <c:choose>
<c:forEach> – For loop
<c:forTokens> – For loop with Delimiter
<c:redirect> – Forwarding to another page
<c:url> – Forward to another url

For using JSTL core in JSP page, We need to import JSTL core library

<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>

The difference between forEach and forTokens is, forEach is similar to for loop in java. forTokens helps us to iterate over a collection by removing the delimiters (i.e .,/'”;:…etc). We will be able to understand once we go through the example code.

Now let us see an example for JSTL core tags,

Most of the functions are self-explanatory as they are similar to java functions.


Leave a Reply

Your email address will not be published. Required fields are marked *