Updated March 21, 2023
What is JSTL?
The JavaServer Pages Standard Tag Library (JSTL) is a collection of JSP tags which encapsulates the core functionality in JSP applications and provides a framework for integrating the existing custom tags with the JSTL tags. It also supports iterations, tags for manipulating XML documents, SQL tags, conditionals, internationalization tags.
Types of JSTL Tags
Types of Java Server Page Standard Tag Library and description are given in the following table.
Tag Library Name |
Prefix | Description |
Core Tags | c | Core tags library contains a set of commonly used JSTL tags that are for URL management, flow control or Iteration, variable supported…to use core tags in JSP. We should add the below code.
|
XML Tags | x | JSTL XML Tag library consist set of tags used to work with XML document such as XML parsing, XPath expression evaluation, XML Transforming etc… Syntax for including XML tag library.
|
SQL Tags | sql | JSTL SQL tag library supports for Interaction with any relational database like SQL, MySQL etc…consist tags for data manipulation like query, update etc….The syntax for including SQL tag library-
|
Formatting Tags | fmt | These formatting tags consist set of tags used for formatting text, date, time and numbers. These helps in developing internationalized websites i.e. i18n through locales and resource bundle.to Include this tag library we include the following code.
|
JSTL Function Tags | fn | JSTL function tag library consists of tags which support to perform basic operations. This library includes most string manipulation tags i.e. concatenation, splitting, substring, etc… To include this library we add the following line.
|
Working of JSTL with Examples
To use these tags following procedure is followed to set up JSTL Tags within the application.
- Download JSTL jars from jakarta.apache.org.Two .jar files are downloaded jstl.jar and standard.jar.
- Add jstl.jar and standard.jar files to WEB-INF/lib directory within the application.
- Include these files in the project classpath.
- To include specific tags in your java program you need a reference of JSTL in your JSP program.
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
- To use Expression Language in JSTL use the following tag lib.
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
Sample Example using tags in JSP:
<c:out value="Hello World" ></c:out>
<c:forEach var="i" begin="1" end="5">
Array: <c:out value="${i}"/><p>
</c:forEach>
<fmt:setTimeZone value="GMT-5" />
<c:set var="date" value="<%=new java.util.Date()%>" />
<x:parse xml="${studentInfo}" var="output"/>
<c:set var="string" value="Hello World"/>
${fn:substring(string, 7, 12)}
<sql:query dataSource="${dataBase}" var="res">
SELECT * from Employee;
</sql:query>
Features of JSTL (JSP Standard Tag Library)
These tags simplified the task of programmers to create websites because these JSP Standard Tag Library tags provide an easy way to maintain JSP pages.
- Core tags in JSTL support for conditional, iterator and URL related actions by simply using tags form tag library.
- JSTLs XML tag library helps the programmer to manipulate XML related actions like iterations or conditional on parsed XML documents.
- It supports interaction with relational databases within the JSP page by using the JSTL SQL Tag library which consists of various tags to deal with the database.
- JSP Standard Tag Library Formatting tag library supports various string manipulation tags such as length, join, replace, etc. The string manipulation process becomes easier using the Formatting tag library.
- It enables the programmer to develop internationalized websites accessible through any locale. This facility is provided by formatting tags which consist of setting locale, date format, time format, etc.
Advantages
Below are some of the advantages explained.
- It Expression Language support java bean examination is automatically done compared with scriptlet in JSP page.
- It Supports standardized internationalization formatting. by using supported tags to formatting numbers, time, date, etc this was not possible in scriptlet coding.
- Easier for a programmer to understand. JSP Standard Tag Library does not follow the complex syntaxes from the OOP language. these tags are based on XML tags those are similar to HTML.
- It provides easy access and manipulation of data.
- Reduces the code complexity single tag can replace lengthy scriptlet code.
- Reusability is achieved by using the JSP Standard Tag Library.
Applications
- One of the most important applications of JSP Standard Tag Library is developing websites which run on various locales.
- Developing dynamic web applications using JSP Standard Tag Library various tags support to develop dynamic web applications.
- Web applications require real-time data manipulation using any relational databases.
- Java applications where expression language is import.
- It is the best fit to develop server-side applications.
Conclusion
As we know JSP Standard Tag Library provides a set of built-in tags that are used to develop dynamic web applications. Including JSTL in JSP benefited the programmer in reducing their work of writing lengthy code. Compared to any other web application programming language JSP becomes a widely-used programming language because of the introduction of JSP Standard Tag Library. Before introducing JSTL even JSP pages also having some limitations, now maximum limitations are reduced.
Recommended Articles
This is a guide to the JSTL. Here we discuss the introduction and types of JSP Standard Tag Library along with the advantages and features of JSP Standard Tag Library. You may also have a look at the following articles to learn more –