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
|xml tag library||Flow Control
|Internationalization tag library||Message Formatting
Number and date formatting
|SQL tag library||Database manipulation||http://java.sun.com/jsp/jstl/sql||sql|
|Functions tag library||Collection length
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:
My book: java 8
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
- Download JSTL.jar and Standarad.jar file from here (or you will get these from your native Apache tomcat installation too!).
- Now put both the files into your ‘WEB-INF/lib’ folder.
- After this, add them to classpath also.
- Finally, you can use JSTL into your project.
- Software Framework vs Library
- FuzzyWuzzy Python library
- Information Technology Infrastructure Library (ITIL)
- Image loading and caching library for Android | Set 1
- Image loading and caching library for Android | Set 2
- Pytube | Python library to download youtube videos
- Learning Model Building in Scikit-learn : A Python Machine Learning Library
- Techniques to be an awesome Agile Developer (Part -1)
- Top Career Paths in Machine Learning
- Saving a file in Git
- Sphere - A Browser for Anonymity
- Self-Driving Car Technology
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.