Expression Language in JSP

What is expression language in JSP?

  • Expression Language (EL) came in JSP 2.0 specification. It makes simpler the accessibility of data stored in Java Bean component.
  • EL is used to create an arithmetic expression as well as logical expression.
  • Expression language has many operators, implicit objects and reserved words.
Syntax:
${expression}

EL Implicit Objects

ObjectsDescriptions
pageScope( )Sets the given attribute name with the value set in the page scope.
requestScope( )Used to access the value of the variable which is set in the request scope.
pageContext( )Sets the context of the page.
sessionScope( )Accesses the value of variable in session scope.
applicationScope( )Accesses the value of the variable which is sent in application scope.
paramMaps the single parameter to the single value.vv
paramValuesMaps the request parameters as a collection of String.
headerContains the HTTP request header as a String value.
headerValuesContains the HTTP request header as a collection of String value.
cookieMaps the given cookie name to the cookie value.

Example: EL using implicit object

//index.jsp

<form method="post" action="welcome.jsp">
     Name: <input type="text" name="user" >
     Password: <input type ="text" name="pass" >
     <input type="submit" value="submit">
</form>

//welcome.jsp

<html>
     <head>
         <title>Welcome Page</title>
     </head>

<body>
        <h1>Welcome ${param.name}</h1>
        <p> Your password is ${param.pass} </p>
</body>
</html>

Basic Operator in EL

The Expression Language supports following basic arithmetic as well as logical operator:

OperatorsDescription
.Access bean property
[ ]Array or list of element.
( )Set the evaluation order by group the expression
+Addition
-Subtraction
*Multiplication
/  or divDivision
% or modModulo
= =  or eqEquality (equal)
! = or neInequality (not equal)
< or ltLess than
> or gtGreater than
< = or leLess than or equal
> = or geGreater than or equal
&& or andLogical AND
| | or orLogical OR
! or notUnary operator
emptyEmpty variable values