JSP Standard Tag Library (JSTL) Tutorial
The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates 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 existing custom tags with JSTL tags. The JSTL tags can be classified, according to their functions, into following JSTL tag library groups that can be used when creating a JSP page: 1. Core Tags
2. Formatting tags
3. SQL tags
4. XML tags
5. JSTL Functions
Install JSTL Library:
If you are using Apache Tomcat container then follow the following two simple steps: 1. Download the binary distribution from Apache Standard Taglib and unpack the compressed file. 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. To use any of the libraries, you must include a <taglib> directive at the top of each JSP that uses the library. Core Tags:
The core group of tags are the most frequently used JSTL tags. Following is the syntax to include JSTL Core library in your JSP:
<%@ taglib prefix="c"
| There are following Core JSTL Tags:
| Like <%= ... >, but for expressions.
| <c:set >
| Sets the result of an expression evaluation in a 'scope'
| <c:remove >
| Removes a scoped variable (from a particular scope, if specified).
| Catches any Throwable that occurs in its body and optionally exposes it.
| Simple conditional tag which evalutes its body if the supplied condition is true.
| Simple conditional tag that establishes a context for mutually exclusive conditional operations, marked by <when> and <otherwise>
| Subtag of <choose> that includes its body if its condition evalutes to 'true'.
| <c:otherwise >
| Subtag of <choose> that follows <when> tags and runs only if all of the prior conditions evaluated to 'false'.
| Retrieves an absolute or relative URL and exposes its contents to either the page, a String in 'var', or a Reader in 'varReader'.
| <c:forEach >
| The basic iteration tag, accepting many different collection types and supporting subsetting and other functionality .
| Iterates over tokens, separated by the supplied delimeters.
| Adds a parameter to a containing 'import' tag's URL.
| <c:redirect >
| Redirects to a new URL.
| Creates a URL with optional query parameters
| Formatting tags:
The JSTL formatting tags are used to format and display text, the date, the time, and numbers for internationalized Web sites. Following is the syntax to include Formatting library in your JSP:
<%@ taglib prefix="fmt"
| Following is the list of Formatting JSTL Tags:
| 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.
Please join StudyMode to read the full document