JSP Expression Language Operators

Chapter 7 - Building JSP Pages Using the Expression Language (EL)

    JSP Expression Language Operators

  • JSP EL Operators:

    1. EL Property Access Operator or Dot (.) Operator JSP EL Dot operator is used to get the attribute values.

    ${firstObj.secondObj}
    

    In this epression, firstObj can be EL implicit object or an attribute in page, request, session or application scope.

    Example:

    ${requestScope.employee.address}
    

    2. JSP EL [] Operator or Collection Access Operator [] operator is more powerful than dot operator. We can use it to get data from List and Array too.

    Examples:

    ${myList[1]} and ${myList["1"]} It provide List or Array index as String literal.
    
    ${myMap[expr]} – if the parameter inside [] is not String, it’s evaluated as an EL.
    ${myMap[myList[1]]} – [] can be nested.
    ${requestScope["foo.bar"]} – cannot use dot operator when attribute names have dots.
    

    3. JSP EL Arithmetic Operators

    Arithmetic operators are provided for simple calculations in EL expressions. They are +, -, *, / or div, % or mod.

    4. JSP EL Logical Operators

    They are && (and), || (or) and ! (not).

    5. JSP EL Relational Operators

    They are == (eq), != (ne), < (lt), > (gt),= (ge).

    JSP EL Operator Precedence

    JSP EL expressions are evaluated from left to right. JSP EL Operator precedence is listed in below table from highest to lowest.

    JSP EL Operator Precedence from Highest to Lowest

    [ ] .
    () – Used to change the precedence of operators.
    - (unary) not ! empty
    * / div % mod
    + – (binary)
    < > = lt gt le ge
    == != eq ne
    && and
    || or
    ? :
    

    JSP EL Reserve Words

    and

    or

    not eq 

    lt

    gt

    le

    ge

    true

    false

    null

    instanceof empty

    div

    mod

© 2015 by Learncertification All Rights Reserved. The certification names are the trademarks of their respective owners. Terms & Privacy Policy