JSP 2.0 Reference
JSP 2.0 Reference
JSP XML
Legend
All tags are case sensitive. A pair of single quotes is equivalent to a pair of double quotes. Spaces are not allowed between an
equals sign and an attribute value.
plain text = required bold = default italics = user-defined | = or ' ' = literal ^ = anything other than
[ ] = optional { } = required choice ... = list of items + = can repeat ( ) = grouped together - = a range
Notes Some action elements have attributes whose value can be computed at request time. In JSP syntax, the format of such a
value is the same as a JSP expression: <%= expression %>. In XML syntax, the format of the value is %= expression %. When
using the JSP expression language (EL), the format of the value in either syntax is ${ expression }.
EL expressions can be quoted by adding a backslash to the front of the expression when the expression language is
enabled. This prevents the expression from being evaluated. Example: \${x+y} will display as ${x+y}.
All elements in XML syntax can contain an xmlns attribute that complies with the XML namespaces spec. This attribute is
used to declare tag libraries and other namespaces. Within the start tag of an element, its syntax is
[xmlns:taglibprefix="URI"]+
All JSP standard actions and custom actions can contain a jsp:attribute standard element as a substitue for any of its
attributes. The jsp:attribute syntax is <jsp:attribute name=attributeName [ trim= "true | false" ] />
If an action contains any jsp:attribute elements and the action also has a body, it must use the jsp:body tag to represent the
body. The jsp:body syntax is <jsp:body> any elements or text </jsp:body>
The Usage column indicates where the element can be used. S = JSP pages. X= JSP documents. TS= tag files in standard
syntax. TX= tag files in XML syntax. A = All.
Comment A Documents the JSP file, but is <%-- comment --%> <!-- comment -->
not included in the response.
The comment can include
anything except --%> (or --> if
the comment is in XML syntax).
Declaration A Declares variables or methods <%! declaration; [ declaration; ]+ ... %> <jsp:declaration>
valid in the page’s scripting code fragment [ declaration; ]+ ...
language. </jsp:declaration>
JSP XML
Scriptlet A Contains a code fragment valid <% code fragment %> <jsp:scriptlet>
in the page’s scripting language. code fragment
</jsp:scriptlet>
JSP XML
Attribute TS, TX Declares an attribute of the <%@ attribute name="attribute-name" <jsp:directive.attribute attributeDirectiveAttrList />
custom tag defined in the tag [ required="true | false" ]
file. [ fragment="true | false" ] where attributeDirectiveAttrList is the same as the list in the
[ rtexprvalue="true | false" ] JSP column.
[ type="java.lang.String | a non-primitive type"]
[ description="text" ]
%>
Include A Includes a file, parsing the file’s <%@ include file="relativeURL" %> <jsp:directive.include file="relativeUR" />
JSP elements.
Page S, X Defines attributes that apply to a <%@ page <jsp:directive.page pageDirectiveAttrList />
JSP page. [ language="java" ] [ extends="package.class" ]
[ import="{package.class | package.*} , ... " ] where pageDirectiveAttrList is the same as the list in the JSP
[ session="true|false" ] column.
[ buffer="none| 8kb|sizekb" ] [ autoFlush="true|false" ]
[ isThreadSafe="true|false" ] [ info="text" ]
[ errorPage="relativeURL" ] [ isErrorPage="true| false" ]
[ contentType="{mimeType [ ; charset=characterSet ] |
text/html ; charset=ISO-8859-1}" ]
[ pageEncoding="{characterSet | ISO-8859-1}" ]
[ isELIgnored="true | false" ]
%>
J AVA S ERVER PAG ES ™ (JSP™) S YNTAX version 2.0
Directives Usage Description Syntax
JSP XML
Tag TS, TX Similar to the page directive in a <%@ tag <jsp:directive.tag tagDirectiveAttrList />
JSP page, but applies to tag files [ display-name="name of the tag file | display-name" ]
instead of JSP pages. As with the [ body-content="scriptless|tagdependent|empty" ] where tagDirectiveAttrList is the same as the list in the JSP
page directive, a translation unit [ dynamic-attributes="page-scoped attribute" ] column.
can contain more than one [ small-icon="relativeURL" ]
instance of the tag directive. All [ large-icon="relativeURL" ]
the attributes apply to the [ description="text" ]
complete translation unit. [ example="text" ]
However, there can be only one [ language="java" ]
occurrence of any attribute or [ import="{package.class | package.*} , ... " ]
value defined by this directive in [ pageEncoding="{characterSet | ISO-8859-1}" ]
a given translation unit. With the [ isELIgnored="true|false" ]
exception of the import attribute, %>
multiple attribute or value
(re)definitions result in a
translation error.
Also used for declaring custom
tag properties such as display
name.
Taglib S, TS Defines a tag library and prefix <%@ taglib {uri="URI" No equivalent. Included in <jsp:root> and in any other XML
for custom tags used in the JSP | tagdir="/WEB-INF/tags[/subdir]+" } prefix="tagPrefix" element using the xmlns attribute instead:
page. %>
<anyxmlelement xmlns:prefix="{uri | urn:jsptld:path |
urn:jsptagdir:/WEB-INF/tags[/subdir]+ }"
>
Examples:
<my:tag xmlns:my="http://example.com/mytaglibrary" />
<my:tag xmlns:my="urn:jsptld:/WEB-INF/tlds/my.tld" />
<my:tag xmlns:my="urn:jsptagdir:/WEB-INF/tags" />
Variable TS, TX Declares an expression language <%@ variable <jsp:directive.variable variableDirectiveAttrList />
variable exposed by the tag to { name-given="scripting variable"
the calling page. | (name-from-attribute="scripting variable" where variableDirectiveAttrList is the same as the list in the
alias="locally-scoped attribute") } JSP column.
[ variable-class="java.lang.String | name of the variable class"
]
[ declare="true | false" ]
[ scope="AT_BEGIN | AT_END | NESTED" ]
[ description="text" ]
%>
J AVA S ERVER PAG ES ™ (JSP™) S YNTAX version 2.0
JSP XML
ELExpression A Allows easy access to application '${' Expression '}' Same as JSP syntax
data stored in JavaBeans
components.
Examples:
<a:tag value="${x+y}" />
<a:tag value="${first} ${last}"/>
<a:tag>${x+y}</a:tag>
ChoiceExpression A If first expression evaluates to Expression ? Expression : Expression Same as JSP syntax
true, evaluate the second
expression; otherwise, evaluate
the third expression.
BinaryOp A Supported arithmetic, logical, and | && | or | || | '+' | '-' | * | / | div | % | mod | > and | && | or | || | '+' | '-' | * | / | div | % | mod | gt
and relational operators. | gt | < | lt | >= | ge | <= | le | == | eq | != | ne | lt | ge | le | == | eq | ne
UnaryOp A Supported unary operators {'-'| ! | not | empty} Same as in JSP syntax
Value A Expresses variables, for example: {ValuePrefix | (Value ValueSuffix) } Same as JSP syntax
sessionScope.cart.numOfItems
param['mycom.productId']
ValuePrefix A The prefix of the variable {Literal | '('Expression')' | ImplicitObject | Java language Same as JSP syntax
expression. For a list of implicit identifier | FuncInvocation}
objects, see the Implicit Objects
for EL Expressions table at the
end of this card.
ValueSuffix A The suffix of the variable {. Identifier | '['Expression']'} Same as JSP syntax
expression. The . operator is
automatically evaluated into the
equivalent [] operator. More
specifically, expr-a.identifier-b is
equivalent to
expr-a["identifier-b"].
Expression Usage Description Syntax
Language
JSP XML
FuncInvocation A Defines a function that can be [Identifier :] Identifier '(' [Expression [',' Expression]+ ] ')' Same as JSP syntax
invoked in an expression. For
example: f:equals(A, B) where f
is the prefix declared in a taglib
directive importing the tag
library that defines the function.
Literal A Supported literals: boolean, {true | false} | (0-9)+ | FloatingPtLiteral | StringLiteral | Same as JSP syntax
integer, floating point, String, null
and null.
Exponent A Represents an exponent used in {e | E} ['+' | -] (0- 9)+ Same as JSP syntax
FloatingPtLiteral
StringLiteral A A string of any characters {'[^(' | \) | \' | \\]+' | "[^(" | \) | \" | \\]+"} Same as JSP syntax. XML syntax rules must be followed
enclosed by single or double with respect to quoting inside attribute values.
quotes: 'string' | "string"
It is possible to use single quotes
within double quotes, and vice
versa, without escaping.
Escape characters:
\\ = Escaped \
\' = Escaped ', valid only inside "
\" = Escaped ", valid only inside '
JSP XML
JSP XML
<jsp:doBody> T Evaluates the body of the tag <jsp:doBody ({var="scopedAttributeName" | Same as JSP syntax.
used by the calling page to varReader="scopedAttributeName" }
invoke this tag file. [scope="page | request | session | application" ] />) | />
<jsp:forward> A Forwards a request to a web <jsp:forward page="{relativeURL | '${' Expression'}' | <jsp:forward page="{relativeURL | '${' Expression'}' |
resource. <%= expression %> }" <%= expression %> }"
{ /> | > [ <jsp:param name="parameterName" { /> | > [ <jsp:param name="parameterName"
value="{parameterValue | '${' Expression '}' | value="{parameterValue | '${' Expression '}' |
<%= expression %>}" } /> ] + %= expression %}" } /> ] +
</jsp:forward> } </jsp:forward> }
<jsp:getProperty> A Inserts the value of a bean <jsp:getProperty name="beanInstanceName" Same as JSP syntax.
property into the result. property="propertyName" />
<jsp:include> A Includes a static file or the <jsp:include page="{relativeURL | '${' Expression '}' | <jsp:include page="{relativeURL | '${' Expression '}' |
result from another web <%= expression %>}" %= expression %}"
component. [ flush="true | false" ] [ flush="true | false" ]
{ /> | > [ <jsp:param name="parameterName" { /> | > [ <jsp:param name="parameterName"
value="{parameterValue | '${' Expression '}' | value="{parameterValue |'${' Expression '}' |
<%= expression %>}" /> ] + %= expression %}" /> ] +
<jsp:invoke> TS, Evaluates a fragment attribute. <jsp:invoke fragment="fragmentName" Same as JSP syntax.
TX
({var="scopedAttributeName" |
varReader="scopedAttributeName"}
[scope="page | request | session | application" ] />) | />
JSP XML
JSP XML
<jsp:text> A Encloses template data, which <jsp:text> Same as JSP syntax. When included in a JSP document, the
is passed through template data template data must be well-formed XML.
uninterpreted to the current </jsp:text>
output while preserving
whitespace.
<tagPrefix:name> Accesses a custom tag’s <tagPrefix:name attribute="value"+ ... /> | <tagPrefix:name attribute="value"+ ... /> |
functionality. <tagPrefix:name attribute="value"+ ... > <tagPrefix:name attribute="value"+ ... >
other tags and data other tags and data
</tagPrefix:name> </tagPrefix:name>
Implicit Objects for Type Scope Some Useful Methods (see class or interface for others)
Scriptlets
response Subclass of javax.servlet.ServletResponse Page Not typically used by JSP page authors
pageContext javax.servlet.jsp.PageContext The context for the JSP page. Provides access to various objects, including servletContext, session, request, and
response.
param java.util.Map Maps a request parameter to a single String parameter value (obtained by calling
ServletReqwuest.getParameter(String name)).
paramValues java.util.Map Maps a request parameter name to an array of String values for that parameter name (obtained by calling
ServletRequest.getParameterValues(String name)).
header java.util.Map Maps a request header name to a single String header value (obtained by calling ServletRequest.getHeader(String
name)).
headerValues java.util.Map Maps a request header name to an array of String values for that header (obtained by calling
ServletRequest.getHeaders(String)).
coookie java.util.Map Maps a cookie name to a single Cookie object. Cookies are retrieved according to the semantics of
HttpServletRequest.getCookies(). If the same name is shared by multiple cookies, an implementation must use the
first one encountered in the array of Cookie objects returned by the getCookies() method. However, the ordering of
cookies is currently unsspecified in the Servlet specification.
initParam java.util.Map Maps a context initialization parameter name to a String parameter value (obtained by calling
ServletContext.getInitparameter(String name)).