0% found this document useful (0 votes)
61 views22 pages

Presented By: Organization Name

The document provides an overview of the JSP Standard Tag Library (JSTL), detailing its purpose and the five main categories: Core, Formatting, SQL, XML, and Functions. It explains how to use JSTL tags in JSP pages, including necessary jar files and syntax for each category. Additionally, it lists various tags within each category along with their descriptions and usage.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views22 pages

Presented By: Organization Name

The document provides an overview of the JSP Standard Tag Library (JSTL), detailing its purpose and the five main categories: Core, Formatting, SQL, XML, and Functions. It explains how to use JSTL tags in JSP pages, including necessary jar files and syntax for each category. Additionally, it lists various tags within each category along with their descriptions and usage.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Organization name

Presented by
 Introduction to JSTL
 Categories
 JSTL Core
 JSTL Formatting
 JSTL SQL
 JSTL XML
 JSTL functions

Reference The Complete Reference JSP 2.0 by -Phil Hanna

JSTL 2
What is JSTL?
• JSP Standard Tag Library(JSTL) is a standard
library of custom tags. The JSTL contain
several tag that can remove scriplet code from
a JSP page.

JSTL 3
Conti..
• JSP Standard Tag Library (JSTL) is the standard
tag library that provides tags to control the JSP
page behavior, iteration and control statements,
internationalization tags, and SQL tags.
•To use JSTL the jar files like Jstl.jar , standard.jar
files are neccesary.

JSTL 4
5 categories
• JSTL Core.
• JSTL Formatting.
• JSTL SQL.
• JSTL XML.
• JSTL functions.

JSTL 5
JSTL core
• 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="http://java.sun.com/jsp/jstl/co
re" prefix="c" %>

JSTL 6
JSTL Formatting
• These tags are provided for formatting of Numbers,
Dates and i18n support through locales and resource
bundles. We can include these tags in JSP with below
syntax

• <%@ taglib
uri="http://java.sun.com/jsp/jstl/fm
t" prefix="fmt" %>

JSTL 7
JSTL SQL
• JSTL SQL Tags provide support for interaction with
relational databases such as Oracle, MySQL etc.
Using SQL tags we can run database queries, we
include it in JSP with below syntax

• <%@ taglib
uri="http://java.sun.com/jsp/jstl/sq
l" prefix="sql" %>

JSTL 8
JSTL XML
• XML tags are used to work with XML documents such
as parsing XML, transforming XML data and XPath
expressions evaluation. Syntax to include XML tags in
JSP page

• <%@ taglib
uri="http://java.sun.com/jsp/jstl/xm
l" prefix="x" %>

JSTL 9
JSTL Functions

• 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

• <%@ taglib
uri="http://java.sun.com/jsp/jstl/fu
nctions" prefix="fn" %>

JSTL 10
JSTL URIs and Default Prefixes

Library URI Prefix


Core http://java.sun.com/jsp/jstl/core c
XML Processing http://java.sun.com/jsp/jstl/xml x
Formatting http://java.sun.com/jsp/jstl/fmt fmt
Database Access http://java.sun.com/jsp/jstl/sql sql
Functions http://java.sun.com/jsp/jstl/functions fn

JSTL 11
JSTL Core Tags
Tags Description
To write something in JSP page, we can use EL also with
<c:out>
this tag
<c:import> Same as <jsp:include> or include directive
<c:redirect> redirect request to another resource
<c:set> To set the variable value in given scope.
<c:remove> To remove the variable from given scope
<c:catch> To catch the exception and wrap it into an object.
Simple conditional logic, used with EL and we can use it
<c:if>
to process the exception from <c:catch>
Simple conditional tag that establishes a context for
<c:choose> mutually exclusive conditional operations, marked by
<c:when> and <c:otherwise>
JSTL 12
Core Tags Library
Tag Descriptor

Sub tags of <c:choose> that includes its body if its


<c:when>
condition evaluates to ‘true’.

Sub tags of <c:choose> that includes its body if its


<c:otherwise>
condition evaluates to ‘false’.

<c:forEach> for iteration over a collection


<c:forTokens> for iteration over tokens separated by a delimiter.
<c:param> used with <c:import> to pass parameters
to create a URL with optional query string
<c:url>
parameters
JSTL 13
Format Tags
Tags Description
To render numerical value with specific
<fmt:formatNumber>
precision or format.
Parses the string representation of a
<fmt:parseNumber>
number, currency, or percentage.
Formats a date and/or time using the
<fmt:formatDate>
supplied styles and pattern
Parses the string representation of a date
<fmt:parseDate>
and/or time
Loads a resource bundle to be used by its
<fmt:bundle>
tag body.
Stores the given locale in the locale
<fmt:setLocale>
configuration variable.
JSTL 14
Format Tags
Tags Description
Loads a resource bundle and stores it in the
<fmt:setBundle> named scoped variable or the bundle
configuration variable.
Specifies the time zone for any time
<fmt:timeZone> formatting or parsing actions nested in its
body.
Stores the given time zone in the time zone
<fmt:setTimeZone>
configuration variable
<fmt:message> To display an internationalized message.
<fmt:requestEncodin
Sets the request character encoding
g>
JSTL 15
SQL Tags
Tags Description
Creates a simple DataSource suitable only for
<sql:setDataSource>
prototyping
Executes the SQL query defined in its body or through
<sql:query>
the sql attribute.
Executes the SQL update defined in its body or
<sql:update>
through the sql attribute.
Sets a parameter in an SQL statement to the specified
<sql:param>
value.
Sets a parameter in an SQL statement to the specified
<sql:dateParam>
java.util.Date value.

Provides nested database action elements with a


<sql:transaction > shared Connection, set up to execute all statements
as one transaction.
JSTL 16
XML tags
Tags Description
Use to parse XML data specified either via an
<x:parse>
attribute or in the tag body.
Sets a variable to the value of an XPath
<x:set >
expression.
Evaluates a test XPath expression and if it is
<x:if > true, it processes its body. If the test
condition is false, the body is ignored.
<x:forEach> To loop over nodes in an XML document.
Simple conditional tag that establishes a
context for mutually exclusive conditional
<x:choose>
operations, marked by <when> and
<otherwise>
Subtag of <choose> that includes its body if
<x:when >
its expression evalutes to 'true'
JSTL 17
XML Tags

Tag Descriptor

Subtag of <choose> that follows <when>


<x:otherwise > tags and runs only if all of the prior
conditions evaluated to 'false'

Applies an XSL transformation on a XML


<x:transform >
document

Use along with the transform tag to set a


<x:param >
parameter in the XSLT stylesheet

JSTL 18
Functions
Function Description
Tests if an input string contains the specified
fn:contains()
substring.

Tests if an input string contains the specified


fn:containsIgnoreCase()
substring in a case insensitive way.

Tests if an input string ends with the specified


fn:endsWith()
suffix.
Escapes characters that could be interpreted
fn:escapeXml()
as XML markup.
Returns the index withing a string of the first
fn:indexOf()
occurrence of a specified substring.
fn:join() Joins all elements of an array into a string.
JSTL 19
Function Description

Returns a string resulting from replacing in an


fn:replace() input string all occurrences with a given
string.
fn:split() Splits a string into an array of substrings.
Tests if an input string starts with the
fn:startsWith()
specified prefix.
fn:substring() Returns a subset of a string.
Returns a subset of a string following a
fn:substringAfter()
specific substring.
Returns a subset of a string before a specific
fn:substringBefore()
substring.
JSTL 20
Tags Description

Converts all of the characters of a string to


fn:toLowerCase()
lower case.

Converts all of the characters of a string to


fn:toUpperCase()
upper case.

Removes white spaces from both ends of a


fn:trim()
string.

JSTL 21
JSTL 22

You might also like