Open In App

JSTL | JSP Standard Tag Library

Improve
Improve
Like Article
Like
Save
Share
Report

Introduction:

Initially, Web designers used scriptlets in JSP pages to generate dynamic content. This resulted in readability issues and also made it difficult to maintain the JSP page. Custom tags were introduced to overcome the problems faced in using scriptlets. Although custom tags proved to be a better choice than scriptlets they had certain limitations too Web designers had to spend a lot of time in coding packaging and testing these tags before using them. This meant that Web designers were often left with little time to concentrate on the designing of Web pages. 

The introduction of JSTL has helped Web designers overcome the shortcomings of custom tags, by encapsulating the common functionalities that the Web designer may need to develop Web pages. These functionalities included the use of tag libraries such as core, SQL and XML. JSTL is Introduced particularly for those Web designers who are not well versed with Java programming JSTL 1.2, introduced in the Java EE 5 platform, aligns with the unified EL. Note that the unified EL helps JavaServer Faces(JSF) to use JSTL tags. The same version of JSTL, i.e. JSTL 1.2, is used in the Java EE 6 platform as well.

Features of JSTL: 

JSTL aims to provide an easy way to maintain SP pages The use of tags defined in JSTL has Simplified the task of the designers to create Web pages. They can now simply use a tag related to the task that they need to implement in a JSP page. The main features of JSTL are as follows:

  • Provides support for conditional processing and Uniform Resource Locator (URL)-related actions to process URL resources in a JSP page. You can also use the JSTL core tag library that provides iterator tags used to easily iterate through a collection of objects.
  • Provides the XML tag library, which helps you to manipulate XML documents and perform actions related to conditional and iteration processing on parsed XML documents.
  • Enables Web applications to be accessed globally by providing the internationalization tag library Internationalization means that an application can be created to adapt to various locales so that people of different regions can access the application in their native languages The internationalization tag library makes the implementation of localization in an application easy, fast and effective.
  • Enables interaction with relational databases by using various SQL commands Web applications require databases to store information required for the application, which can be manipulated by using the SQL tag library provided by JSTL.
  • Provides a series of functions to perform manipulations, such as checking whether an input String contains the substring specified as a parameter to a function or returning the number of items in a collection, or the number of characters in a 5tring These functions can be used in an El expression and are provided by the functions tag library.

Tag Libraries in JSTL: 

A tag library provides a number of predefined actions that behind functionalities to a specific JSP page. JSTL provides tag libraries that include a wide range of actions to perform common tasks. For example, if you want to access data from database, you can use SQL tag library in your applications. JSTL is a standard tag library that is composed of five tag libraries. Each of these tag libraries represents separate functional area and is used with a prefix. Below table describes the tag libraries available in JSTL.
 

Name of the Tag Library Function URI Prefix
Core tag library variable support
Flow Control
Iterator
URL management
Miscellaneous
Core
http://java.sun.com/jsp/jstl/core c
xml tag library Flow Control
Transformation
Locale
http://java.sun.com/jsp/jstl/xml x
Internationalization tag library Message Formatting
Number and date formatting
http://java.sun.com/jsp/jstl/fmt fmt
SQL tag library Database manipulation http://java.sun.com/jsp/jstl/sql sql
Functions tag library Collection length
String manipulation
http://java.sun.com/jsp/jstl/functions fn

Example of JSTL:

The <c:set> Tag with body
variable can be set by using the <c:set> tag within the body of another tag as in the following code snnipate: 

<c:set var="bookname"> 
My book: java 8 
</c:set> 
<c:out value="${bookname}"/> 

In the preceding code snippet, the value for the bookname variable is set in the body of the <c:set> tag. Here <c:out> tag is used for printing the output.

How to download and install JSTL: 

  1. Download JSTL.jar and Standard.jar file from here (or you will get these from your native Apache tomcat installation too!).
  2. Now put both the files into your ‘WEB-INF/lib’ folder.
  3. After this, add them to classpath also.
  4. Finally, you can use JSTL into your project.

Last Updated : 01 Nov, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads