Open In App

JSTL | JSP Standard Tag Library

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:

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.
Article Tags :