JSP Expression Language - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

JSP Expression Language

Description:

Introduced as part of standard JSP in version 2.0. simple expression language for accessing variables. starts with the ${ delimiter and ends with } ... – PowerPoint PPT presentation

Number of Views:279
Avg rating:3.0/5.0
Slides: 13
Provided by: tkl1
Category:

less

Transcript and Presenter's Notes

Title: JSP Expression Language


1
JSP Expression Language
Celsina Bignoli bignolic_at_smccd.net
2
Expression Language
  • Introduced as part of standard JSP in version 2.0
  • simple expression language for accessing
    variables
  • starts with the delimiter and ends with
  • anExpression
  • Case sensitive. All keywords are lowercase

3
Using Expressions
  • in static text
  • The value of the expression is computed and
    inserted into the current output
  • In any standard or custom tag attribute that can
    accept an expression
  • ltsometag value"expr"/gt
  • The expression is evaluated and the result is
    coerced to the attribute's expected type
  • ltsometag value"someexprexprtextexpr"
    /gt
  • The expressions are evaluated from left to right.
    Each expression is coerced to a String and then
    concatenated with any intervening text. The
    resulting String is then coerced to the
    attribute's expected type.

4
Variables
  • The web container evaluates a variable that
    appears in an expression by looking up its value
    according to the behavior of PageContext.findAttri
    bute(String).
  • For example, when evaluating the expression
    product, the container will look for product
    in the following scopes
  • page
  • request
  • session
  • application
  • If product is not found, null is returned.

5
Variables
  • Properties of variables are accessed using the .
    operator and can be nested arbitrarily
  • For example
  • pageContext.session
  • myBean.attribute1.attribute2

6
Implicit Variables
  • pageContext The context for the JSP page.
    Provides access to various other objects
    including
  • session The session object for the client.
  • request The request triggering the execution of
    the JSP page.
  • response The response returned by the JSP page.

7
Implicit Variables
  • param Maps a request parameter name to a single
    value
  • ltcout valueparam.userName /gt
  • paramValues Maps a request parameter name to an
    array of values
  • header Maps a request header name to a single
    value
  • headerValues Maps a request header name to an
    array of values
  • cookie Maps a cookie name to a single cookie
  • initParam Maps a context initialization
    parameter name to a single value

8
Implicit Variables
  • pageScope Maps page-scoped variable names to
    their values
  • requestScope Maps request-scoped variable names
    to their values
  • sessionScope Maps session-scoped variable names
    to their values
  • applicationScope Maps application-scoped
    variable names to their values

9
Literals
  • The JSP expression language defines the following
    literals
  • Boolean true and false
  • Integer as in Java
  • Floating point as in Java
  • String with single and double quotes " is
    escaped as \", ' is escaped as \', and \ is
    escaped as \\.
  • Null null

10
Literals
  • the JSP expression language provides the
    following operators
  • Arithmetic , - (binary), , / and div, and
    mod, - (unary)
  • Logical and, , or, , not, !
  • Relational , eq, !, ne, lt, lt, gt, gt, lt, ge,
    gt, le. Comparisons can be made against other
    values, or against boolean, string, integer, or
    floating point literals.
  • Empty The empty operator is a prefix operation
    that can be used to determine whether a value is
    null or empty.
  • Conditional A ? B C. Evaluate B or C,
    depending on the result of the evaluation of A.

11
Reserved Words
  • The following words are reserved for the JSP
    expression language and should not be used as
    identifiers
  • and   eq   gt   true   instanceof
    or    ne   le   false  empty not   lt   ge   null 
      div   mod

12
Example
  • 4.0 gt 3 true
  • empty param.add true if parameter add in the
    request is null or empty string
  • pageContext.request.contextPath The context
    path
  • sessionScope.cart.numberOfItems The value of
    the numberOfItems property of the session-scoped
    attribute named cart
Write a Comment
User Comments (0)
About PowerShow.com