JSTL Tutorial with Examples – JSTL Core Tags

Introduction :

JSTL stands for JavaServer Pages Standard Tab Library. It is a set of Java tag libraries that will simplify and reduce java codes in your JSP page.

To simplify the developer task SUN has implemented some standard tags for the commonly used scenario like iteration, conditional checks, data formatting, localization etc. JSP Standard Tag Library (JSTL) was introduced to ease the programming in JSP by storing generic tasks in tag libraries under four different categories.

To use JSTL you would have to first download the JSTL JAR and standard.jar. Then it should be kept inside the lib folder of the web server/application server or these jars should be added to your application class-path.If you have maven project, below dependencies should be added in pom.xml file.

Introduction :

JSTL stands for JavaServer Pages Standard Tab Library. It is a set of Java tag libraries that will simplify and reduce java codes in your JSP page.

To simplify the developer task SUN has implemented some standard tags for the commonly used scenario like iteration, conditional checks, data formatting, localization etc. JSP Standard Tag Library (JSTL) was introduced to ease the programming in JSP by storing generic tasks in tag libraries under four different categories.

To use JSTL you would have to first download the JSTL JAR and standard.jar. Then it should be kept inside the lib folder of the web server/application server or these jars should be added to your application class-path.If you have maven project, below dependencies should be added in pom.xml file.



<dependency>
    <groupId>jstl</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>
<dependency>
    <groupId>taglibs</groupId>
    <artifactId>standard</artifactId>
    <version>1.1.2</version>
</dependency>

Based on the functionalities JSTL, tags can be classified into following categories.

  • JSTL Core Tags
  • JSTL XML Tags
  • JSTL Formatting Tags
  • JSTL SQL Tags


JSTL Core Tags :

JSTL Core Tags are used to perform basic operations like iterating on data collection, apply the conditional statements, set the parameter etc.

To use JSTL tag in JSP you need to write the following taglib directive in the JSP.

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

Following are the commonly used tags of JSTL core tag library that can be used in the JSP pages.

Tag Description
<c:out> To write something in JSP page, we can use EL also with this tag
<c:import> Same as <jsp:include> or include directive
<c:redirect> redirect request to another resource
<c:set> To set the variable value in given scope.
<c:remove> To remove the variable from given scope
<c:catch> To catch the exception and wrap it into an object.
<c:if> Simple conditional logic, used with EL and we can use it to process the exception from <c:catch>
<c:choose> Simple conditional tag that establishes a context for mutually exclusive conditional operations, marked by <c:when> and <c:otherwise>
<c:when> Subtag of <c:choose> that includes its body if its condition evalutes to ‘true’.
<c:otherwise> Subtag of <c:choose> that includes its body if its condition evalutes to ‘false’.
<c:forEach> for iteration over a collection
<c:forTokens> for iteration over tokens separated by a delimiter.
<c:param> used with <c:import> to pass parameters
<c:url> to create a URL with optional query string parameters




comments powered by Disqus