Jsp expression language
This presentation is the property of its rightful owner.
Sponsored Links
1 / 12

JSP Expression Language PowerPoint PPT Presentation


  • 135 Views
  • Uploaded on
  • Presentation posted in: General

JSP Expression Language. Celsina Bignoli [email protected] 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.

Download Presentation

JSP Expression Language

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Jsp expression language

JSP Expression Language

Celsina Bignoli

[email protected]


Expression language

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


Using expressions

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

    <some:tag value="${expr}"/>

    • The expression is evaluated and the result is coerced to the attribute's expected type

      <some:tag value="some${expr}${expr}text${expr}"/>

    • 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.


Variables

Variables

  • The web container evaluates a variable that appears in an expression by looking up its value according to the behavior of PageContext.findAttribute(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.


Variables1

Variables

  • Properties of variables are accessed using the “. “ operator and can be nested arbitrarily

  • For example:

    • ${pageContext.session}

    • ${myBean.attribute1.attribute2}


Implicit variables

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.


Implicit variables1

Implicit Variables

  • param: Maps a request parameter name to a single value

    • <c:out value=“${param.userName}” />

  • 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


Implicit variables2

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


Literals

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


Literals1

Literals

  • the JSP expression language provides the following operators:

    • Arithmetic: +, - (binary), *, / and div, % and mod, - (unary)

    • Logical: and, &&, or, ||, not, !

    • Relational: ==, eq, !=, ne, <, lt, >, gt, <=, ge, >=, 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.


Reserved words

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


Example

Example

  • ${4.0 > 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


  • Login