- This is my JSTL Tutorial which is about JSTL (JSP Tag Libraries) that gives you a clear understanding about all the JSTL tags and their functionalities with practical code implementations for each tags.
- The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates the core functionality common to many JSP applications.
- JSTL has support for common, structural tasks such as iteration and conditionals, tags for manipulating XML documents, internationalization tags, and SQL tags.
- It also provides a framework for integrating the existing custom tags with the JSTL tags.
- To begin working with JSP tages you need to first install the JSTL library.
- If you are using the Apache Tomcat container, then follow these two steps β
- Download the binary distribution from Apache Standard Taglib and unpack the compressed file.
Download JAR Files here : JSTL JAR 1.2
β To use the Standard Taglib from its Jakarta Taglibs distribution, simply copy the JAR files in the distribution's 'lib' directory to your application's webapps\ROOT\WEB-INF\lib directory.
[Note: If you are creating a Maven Project, use the following dependency to add JSTL Jar files]
<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>
To use any of the libraries, you must include a directive at the top of each JSP that uses the library.
- Fast Development - JSTL provides many tags that simplify the JSP
- Code Reusability - We can use the JSTL tags on various pages
- No need to use scriptlet tag - It avoids the use of scriptlet tag
-
JSTL Core tags provide support for iteration, conditional logic, catch exception, url, forward or redirect response etc.
-
To use JSTL core tags, we should include it in the JSP page like below.
<%@ taglib uri="https://java.sun.com/jsp/jstl/core" prefix="c" %>
-
JSTL Formatting tags are provided for formatting of Numbers, Dates and i18n support through locales and resource bundles.
-
We can include these jstl tags in JSP with below syntax:
<%@ taglib uri="https://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
-
JSTL SQL Tags provide support for interaction with relational databases such as Oracle, MySql etc.
-
Using JSTL SQL tags we can run database queries, we include these JSTL tags in JSP with below syntax:
<%@ taglib uri="https://java.sun.com/jsp/jstl/sql" prefix="sql" %>
-
JSTL XML tags are used to work with XML documents such as parsing XML, transforming XML data and XPath expressions evaluation. -Syntax to include JSTL XML tags in JSP page is:
<%@ taglib uri="https://java.sun.com/jsp/jstl/xml" prefix="x" %>
-
JSTL tags provide a number of functions that we can use to perform common operation, most of them are for String manipulation such as String Concatenation, Split String etc.
-
Syntax to include JSTL functions in JSP page is:
<%@ taglib uri="https://java.sun.com/jsp/jstl/functions" prefix="fn" %>
- To write something in JSP page, we can use EL also with this tag
- Same as jsp:include or include directive
- redirect request to another resource
- To set the variable value in given scope.
- To remove the variable from given scope
- To catch the exception and wrap it into an object.
- Simple conditional logic, used with EL and we can use it to process the exception from <c:catch>
- Simple conditional tag that establishes a context for mutually exclusive conditional operations, marked by <c:when> and <c:otherwise>
- Subtag of <c:choose> that includes its body if its condition evalutes to βtrueβ.
- Subtag of <c:choose> that includes its body if its condition evalutes to βfalseβ.
- for iteration over a collection
- for iteration over tokens separated by a delimiter.
- used with <c:import> to pass parameters
- To create a URL with optional query string parameters
- To render numerical value with specific precision or format.
- Parses the string representation of a number, currency, or percentage.
- Formats a date and/or time using the supplied styles and pattern.
- Parses the string representation of a date and/or time
- Loads a resource bundle to be used by its tag body.
- Stores the given locale in the locale configuration variable.
- Loads a resource bundle and stores it in the named scoped variable or the bundle configuration variable.
- Specifies the time zone for any time formatting or parsing actions nested in its body.
- Stores the given time zone in the time zone configuration variable
- Displays an internationalized message.
- Sets the request character encoding
- Creates a simple DataSource suitable only for prototyping
- Executes the SQL query defined in its body or through the sql attribute.
- Executes the SQL update defined in its body or through the sql attribute.
- Sets a parameter in an SQL statement to the specified value.
- Sets a parameter in an SQL statement to the specified java.util.Date value.
- Provides nested database action elements with a shared Connection, set up to execute all statements as one transaction.
- Like <%= ... >, but for XPath expressions.
- Used to parse the XML data specified either via an attribute or in the tag body.
- Sets a variable to the value of an XPath expression.
- Evaluates a test XPath expression and if it is true, it processes its body. If the test condition is false, the body is ignored.
- To loop over nodes in an XML document.
- Simple conditional tag that establishes a context for mutually exclusive conditional operations, marked by and tags.
- Subtag of that includes its body if its expression evalutes to 'true'.
- Subtag of that follows the tags and runs only if all of the prior conditions evaluates to 'false'.
- Applies an XSL transformation on a XML document
- Used along with the transform tag to set a parameter in the XSLT stylesheet
- Tests if an input string contains the specified substring.
- Tests if an input string contains the specified substring in a case insensitive way.
- Tests if an input string ends with the specified suffix.
- Escapes characters that can be interpreted as XML markup.
- Returns the index withing a string of the first occurrence of a specified substring.
- Joins all elements of an array into a string.
- Returns the number of items in a collection, or the number of characters in a string.
- Returns a string resulting from replacing in an input string all occurrences with a given string.
- Splits a string into an array of substrings.
- Tests if an input string starts with the specified prefix.
- Returns a subset of a string.
- Returns a subset of a string following a specific substring.
- Returns a subset of a string before a specific substring.
- Converts all of the characters of a string to lower case.
- Converts all of the characters of a string to upper case.
- Removes white spaces from both ends of a string.
For more queries, reach me through [email protected] or whatsapp @ 9698382306
Code and documentation Copyright 2021 : Gowthamraj K