×
☰ See All Chapters

Expression Language (EL) in JSP

Expression Language (EL) was introduced in JSP 2.0 version. EL is the easiest way of invoking java code. EL expressions increase JSP code readability and reusability. EL expressions are always within curly braces and prefixed with the dollar sign.

Expression Language Syntax

${expr}

${ expr. expr }

${ expr [expr] }

expr can be any one of the following

  • Java expression resulting into any value. 

  • Java variable containing any value. 

In EL there are two access operators.

  1. . (dot) operator 

  2. [ ] (bracket) operator 

jsp-expression-language-0
 

Example

<html>

<body bgcolor="yellow">

                ${100}<br>

                ${44.13}<br>

                ${"Hello"}<br>

                ${true}<br>

                ${5+7}<br>

                ${6/3}<br>

                ${5>2}

</body>

</html>

 

jsp-expression-language-1
 

Implicit Objects in Expression Language

EL implicit and JSP implicit objects are different except pageContext. pageContext implicit object is same in and refers to the object of javax.servlet.jsp.PageContext. All the EL implicit objects are of type java.util.Map.

Implicit Objects

Usage

applicationScope

A java.util.Map having the values of named attributes in application scope

cookie

A java.util.Map having cookie names and their values.

header

A java.util.Map that links parameter names to String arrays corresponding to ServletRequest.getParameterValues(String name)

headerValues

A java.util.Map having header names and their values.

initParam

A java.util.Map having context initialization parameter names and their values.

pageContext

The JSP PageContext object.

pageScope

A java.util.Map having the values of named attributes in page scope

param

A java.util.Map having the values of named attributes in

paramValues

A java.util.Map that links parameter names to their ServletRequest.getParameter(String name)

requestScope

A java.util.Map having the values of named attributes in request scope

sessionScope

A java.util.Map having the values of named attributes in session scope

Example for expression language with implicit objects

login.html

<html>

<body bgcolor='wheat'>

        <h1>WELCOME TO LOGIN PAGE</h1>

        <form action="../jsp/withEL.jsp">

                FIRST NAME:<input type="text" name="fname">

                LAST NAME:<input type="text" name="lname">

                PRIMARY PHONE:<input type="text" name="ph">

                SECONDARY PHONE:<input type="text" name="ph">

                <input type="submit" value="SUBMIT">

        </form>

</body>

</html>

 

jsp-expression-language-2
 

All Chapters
Author