Professional Documents
Culture Documents
JSTL Quick Reference SDF
JSTL Quick Reference SDF
headerValues
cookie
initParam
Expressions (EL)
In Attribute Values
<a:tag value="${expr}"/>
<a:tag value="me${expr} ${expr}"/>
Bean Property Access
bean.name
bean["name"]
bean.property[index]
Map Property Access
bean.property["key"]
Arithmetic Operators
Operator
Description
Addition
Subtraction
Multiplication
/ (div)
Division
% (mod)
Remainder (modulus)
Description
Equality
pageScope
< (lt)
Less than
> (gt)
Greater than
<= (le)
>= (ge)
<= (le)
param
paramValues
header
Description
empty
()
Function
fn:contains
Inequality
Operator
!= (ne)
sessionScope
Other Operators
pageContext
requestScope
! (not)
Description
Description
== (eq)
Operator
Relational Operators
Operator
Description
(string, substring) :
boolean
Operator
fn:endsWith
(string, suffix) :
boolean
(string) : String
Description
&& (and)
|| (or)
fn:escapeXml
Logical Operators
Description
fn:indexOf
(string, substring) : int
Function
fn:join
(string[], separator) :
String
fn:length
(collection or string) :
int
fn:replace
Description
General-Purpose Actions
Actions for rendering data, creating and
modifying scoped variables, and catching
exceptions.
Rqd
Default
value
Data to output
Yes
None
default
No
Body
escapeXml
true
No
true
Description
var
Yes
None
scope
Scope of variable
No
All
scopes
Attribute
var
Description
Name of variable to hold the
thrown exception, if any.
Variable will be of type
java.lang.Throwable.
Rqd
No
Default
None
Conditional Actions
Actions for processing markup based on logical
conditions.
Attribute
Returns the subset of string that
procedes the given substring.
to escape special
characters
Default
<c:catch var="err">
<c:import value="http://java.sun.com"/>
</c:catch>
<c:if test="${not empty err}">
Could not connect to Java web site.
</c:if>
Rqd
Attribute
Description
Rqd
Default
value
Data to save
No
Body
target
No
None
property
No
None
var
No
None
scope
Scope of variable
No
page
Description
Rqd
Default
test
Condition to evaluate
Yes
None
var
No
None
scope
Scope of variable
No
page
Attribute
varStatus
Description
Condition to evaluate
Rqd
Yes
None
Iterator Actions
Actions that loop over collections, for a fixed number
of times, or over a set of string tokens. These
actions share the following attributes for iterating over
a subset of elements.
begin
end
step
Rqd
No
No
No
None
Attribute
Default
0
Last item
1
Description
Rqd
Default
var
No
None
items
None
Yes
delims
Yes
None
first boolean
indicator if this is the first
iteration
Description
Name of variable to hold
the current item. This
variable has only nested
visibility.
Rqd
Default
No
None
<c:set var="users">Fred,Joe,Mary<c:set>
<c:forTokens var="name" items="${users}"
delims=",">
<c:out value="${name}"/><br/>
</c:forTokens>
Description
Rqd
Default
Description
Rqd
Default
url
Yes
None
context
No
Current
context
var
No
None
scope
No
page
varReader
No
None
None
Attribute
Attribute
<c:forEach items="${user.languages}"
var="lang" varStatus="status">
<c:if test="${status.first}">
You speak these languages:<br><ul>
</c:if>
<li><c:out value="${lang}"/></li>
<c:if test="${status.last}"></ul></c:if>
</c:forEach>
items
Default
var
Description
Rqd
Default
Attribute
Description
Attribute
Attribute
Description
Rqd
Default
value
URL to be processed.
Yes
None
context
No
Current
context
var
No
None
scope
No
page
Description
Rqd
Default
url
Yes
None
context
No
Current
context
Description
Rqd
name
Yes
value
Default
None
Description
Rqd
Default
Yes
None
value
String representation of a
locale (e.g. en_US) or an
actual java.util.Locale object.
variant
None
scope
page
Body
Description
Rqd
Default
None
prefix
None
Description
Attribute
value
Rqd
None
var
Default
l10n
context
(see
Configu
ration)
No
No
page
<fmt:message key="title"
bundle="${strutsResources}"/>
Description
Rqd
key
No
bundle
var
No
scope
No
Rqd
No
Default
Body
Default
Body
Default
l10n
context
<fmt:setTimeZone var="mtnTime"
value="America/Denver"/>
Mountain Time: <fmt:formatDate
type="time" timeStyle="short"
value="${now}" timeZone="${mtnTime}"/>
Attribute
Attribute
Description
Character encoding (e.g. UTF8) to use.
Rqd
No
<jsp:useBean id="now"
class="java.util.Date"/>
<fmt:timeZone
value="America/Los_Angeles">
Pacific Time:<fmt:formatDate
type="time" timeStyle="short"
value="${now}"/>
</fmt:timeZone>
<br/>
Local Time:<fmt:formatDate type="time"
timeStyle="short" value="${now}"/>
No
Default
time zone
(see
Configur
ation)
scope
No
page
value
Yes
Rqd Default
Numeric value to
format.
type
Default
None
Description
value
page
Rqd
Default
var
Automatic
Description
Rq
d
Default
Formatting Actions
Actions that format and parse numbers,
currencies, percentages, dates and times.
Attribute
Description
value
<fmt:requestEncoding key="ISO-8859-1"/>
value
Attribute
Description
Default
basename
scope
<fmt:message key="fieldRequired">
<fmt:param value="User ID"/>
</fmt:message>
pattern
No
Body
number
number
currency
percentage
Custom formatting
No
pattern (overrides other
formatting options
including type see
java.text.DecimalFormat
)
None
Attribute
currencyCode
currencySymbol
groupingUsed
Description
Rqd Default
Based
on
default
locale
No
Based
on
default
locale
Specifies if grouping
separators will be used
(for example
formatting 23890 as
23,890).
No
true
No
None
minIntegerDigits
Minimum number of
digits to print in the
integer part of the
number.
No
None
No
minFractionDigit
s
Minimum number of
digits to print in the
fractional part of the
number.
No
None
var
No
None
scope
No
page
None
Attribute
Rqd
Default
value
Value to parse.
No
Body
type
No
number
pattern
No
String representation of a
locale (e.g. en_US) or an
actual java.util.Locale
object used for parsing.
No
integerOnly
No
false
var
No
None
scope
No
page
parseLocale
Attribute
timeStyle
Description
Rqd
Default
default
number
currency
percentage
None
pattern
None
timeZone
Default
time
zone
Default
locale
No
Formatting Dates
Dates are formatted and parsed using the
<fmt:formatDate> and <fmt:parseDate>
actions which share the following common
attributes.
Attribute
Description
type
Description
Specifies the type of value. Valid
values are:
dateStyle
Rqd
No
Default
date
default
Attribute
Description
Rqd Default
value
No
None
var
No
None
scope
No
page
Attribute
Description
Rqd Default
value
No
None
parseLocale
String representation of a
locale (e.g. en_US) or an
actual java.util.Locale object
used for parsing.
No
Default
locale
var
No
None
scope
No
page
Attribute
scope
Attribute
sql
Description
SQL query to execute.
Rqd
No
maxRows
Default
maxRows
(see
Configur
ation)
No
startRow
No
var
None
No
Default
page
<sql:update var="updateCount">
UPDATE users SET first_name="William" WHERE
first_name = "Bill"
</sql:update>
<c:out value="${updateCount} rows updated."/>
Attribute
Description
Rqd
Default
sql
No
Body
dataSource
No
Default
data
source
var
None
scope
No
page
Body
Default
data
source
Rqd
Default
Description
<sql:transaction>
<sql:update sql="DELETE users WHERE
user_name='bsiggelkow'"/>
<sql:update sql="INSERT INTO users
VALUES ('billsigg','Bill','Siggy')"/>
</sql:transaction>
Attribute
dataSource
isolation
Description
Rqd
Database connection to
No
use. A
javax.sql.DataSource
object, or a String
representing a JNDI
resource or the parameters
for java.sql.DriverManager.
Default
data
source
(see
Configu
ration)
Databas
e 's
default
No
dataSource
Description
Rqd
Default
Database connection to
No
use or create. A
javax.sql.DataSource
object, or a String
representing a JNDI
resource or the parameters
for
java.sql.DriverManager.
None
driver
No
None
url
No
None
Description
Rqd
Default
user
None
password
No
None
var
No
Default
data
source
name
(see
Configur
ation)
Default
Attribute
Attribute
scope
No
page
Attribute
value
Description
Rqd
Default
Body
Attribute
Description
Rqd
Default
value
Yes
None
type
No
timestamp
scope="page"/>
Function
XPath Axis
(string1, string2):
boolean
count
(node-set):
contains
Example
descendant
$doc//first-name
floor
self
$doc/users/user/.
(number or
object):
..
parent
$doc//[firstname='George']/../lastname
attribute
child
(blank)
(matches any
namespace)
$doc//user[@id="997"]/firs
t-name
last():
number
local-name
(node-set):
$doc//*[localname()='users']/user
name
string
(node-set):
string
Function
ceiling
(number or
object):
Description
Returns the smallest integer greater than or
equal to number or object (as converted as
if by the number() function).
number
concat
(string1, string 2,
...):
string
namespace-uri
(node-set):
string
not
(boolean or
object):
boolean
number
(object):
number
number
$doc/users/user[lastname='Burdell']
number
//
Description
position():
number
Function
round
(number or
object):
number
starts-with
(string1,string2):
Description
Returns the closest integer to number or
object (as converted as if by the number()
function). If two integers are equally close,
the value closer to positive infinity is
chosen. (e.g. round(3.5) returns 4, round(3.5) returns -3).
Returns true if string1 starts with string2;
false, otherwise.
boolean
string
(object):
string
string-length
(object):
number
substring
(string, index,
length):
string
substring-after
(string1, string2):
string
substring-before
(string1, string2):
string
sum
(node-set):
number
expression as a string.
<title>feed title</title>
<link>source url</link>
<description>feed desc</description>
<item>
<title>article title</title>
<link>article url</link>
<description>article
desc</description>
</item>
<item>
<title>article title</title>
<link>article url</link>
<description>article
desc</description>
</item>
</channel>
</rss>
RSS Channel:
<x:out select="$news//channel/title"/>
Attribute
Attribute
Description
Rqd
Default
doc
No
Body
xml
No
Body
systemId
No
filter
var
Description
Rqd
Default
select
XPath expression.
Yes
None
escapeXml
true
No
true
to escape special
characters
Attribute
Description
Rqd
Default
select
XPath expression.
No
None
var
No
None
No
page
Boolean
java.lang.Boolean
None
Number
java.lang.Number
No
None
Yes
None
scope
No
page
varDom
Yes
None
No
page
scope
<x:if select=
"$news//item[contains(description,'Linux')]">
Linux is in the news today!
</x:if>
Attribute
select
Description
Test condition as an XPath
expression. Body content is
processed if the condition is
true.
Rqd
Yes
Default
None
var
None
scope
Scope of variable
page
No
Description
Rqd
Default
Yes
None
Attribute
select
Description
Name of variable to hold
the current item. This
variable has only nested
visibility.
Rqd Default
No
None
select
var
Description
Transformation Actions
Attribute
Attribute
<c:set var="xsl">
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform
">
<xsl:template match="item">
<li>
<xsl:value-of select="title"/>
</li>
</xsl:template>
<xsl:template match="/">
<ol>
<xsl:apply-templates
select="//item"/>
</ol>
</xsl:template>
</xsl:stylesheet>
</c:set>
<x:transform xml="${news}"
xslt="${xsl}"/>
Attribute
doc
Rqd Default
No
None
Description
Rqd
No
(JSTL 1.1) Source XML
document for the
transformation. Value can
be a String, Reader,
javax.xml.transform.Source
, org.w3c.dom.Document,
or any value exported
<x:parse> or <x:set>. If the
value comes from <x:set> it
cannot be a partial
document.
Default
Body
Attribute
Description
Rqd
Default
Attribute
JSTL Configuration
Body
docSystemId
No
None
xmlSystemId
No
None
xslt
None
No
None
No
Non e
var
scope
result
javax.xml.transform.Result
object that holds or
processes the transformed
XML.
Body
import javax.servlet.jst.jstl.core.Config;
...
Config.set( session,
Config.FMT_LOCALE,
new java.util.Locale(en_US") );
No
None
<x:transform xml="${news}"
xslt="${searchXsl}"/>
<x:param name="searchParam">
Web Services
</x:param>
</x:transform>
Description
None
Attribute
Yes
Default
value
Rqd
xml
xsltSystemId
name
Description
Rqd
Default
<web-app>
...
<context-param>
<param-name>
javax.servlet.jsp.jstl.fmt.locale
</param-name>
<param-value>
en_US
</param-value>
</context-param>
...
</web-app>
Locale
Specifies the default locale to be used by the
formatting tags. This variable sets an applicationbased locale and has priority over any browser-based
locales.
Variable Name
javax.servlet.jsp.jstl.fmt.timeZone
Java Constant
Config.FMT_TIMEZONE
Type
Set by
Data Source
Specifies the data source to be accessed by the SQL
tags. The value can be specified as a
javax.sql.DataSource object, as a string representing
a JNDI relatove path (e.g. jdbc/myDatabase if the
absolute JNDI name is
java:comp/env/jdbc/myDatabase), or a JDBC
parameters string (url, driver, user, password) (e.g.
jdbc:mysql://localhost/,com.mysql.Driver).
Variable Name
javax.servlet.jsp.jstl.fmt.locale
Java Constant
Config.FMT_LOCALE
Type
Set by
Java Constant
Config.SQL_DATA_SOURCE
Type
Set by
Fallback Locale
Specifies the default locale to be used for finding
resource bundle messages. This locale will be used
if a message cannot be found using any of the
preferred locales.
Variable Name
javax.servlet.jsp.jstl.fmt.fallbackLocale
Java Constant
Config.FMT_FALLBACK_LOCALE
Type
Set by
Config.FMT_LOCALIZATION_CONTEXT
Type
String (e.g.
resources.ApplicationResources) or
javax.servlet.jsp.jstl.fmt.LocalizationConte
xt
Set by
Time Zone
Specifies the default time zone to be used by the
formatting tags.
Variable Name
javax.servlet.jsp.jstl.fmt.timeZone
Max Rows
Sets the maximum number of rows that can be
returned by any <sql:query> tag. A value of -1
indicates no limit.
Variable Name javax.servlet.jsp.jstl.sql.maxRows
Java Constant
Config.SQL_MAX_ROWS
Type
Integer
Set by