logo

Expression Language(EL) In JSP


Show

The Expression Language (EL) clarifies the availability of information saved withinside the Java Bean component, and different items like request, session, application, etc.

There are many implicit objects, operators, and reserve phrases in EL.

It is the latest added characteristic in JSP technology version 2.0

Syntax of Expression Language (EL)

${ expression }

Implicit Objects in Expression Language (EL)

Many implicit objects are there in the Expression Language. All are given below:

Implicit Objects

Usage

pageScope

it maps the mentioned attribute name with the value set in the page extent

requestScope

it maps the mentioned attribute name with the value set in the request extent

sessionScope

it maps the mentioned attribute name with the value set in the session extent

applicationScope

it maps the mentioned attribute name with the value set in the application extent

param

it maps the appeal parameter to the individual value

paramValues

it maps the appeal parameter to an array of values

header

it maps the appeal header name to the individual value

headerValues

it maps the appeal header name to an array of values

cookie

it maps the mentioned cookie name to the cookie value

initParam

it maps the started parameter

pageContext

it provides an approach to many objects request, sessions, etc

EL Param Example

In this example, we've produced documents index.jsp and process.jsp. The index.jsp document receives input from the person and sends the request to the process.jsp which in turn prints the identity of the person using EL.

index.jsp

<form action="process.jsp">  
Enter Name:<input type="text" name="name" /><br/><br/>  
<input type="submit" value="go"/>  
</form>

process.jsp

Welcome, ${ param.name } 

download this example

EL Session Scope Example

In this example, we print the information saved withinside the session scope the usage of EL. For this motive, we've made use of a sessionScope object.

index.jsp

<h3>welcome to index page</h3>  
<%  
session.setAttribute("user","sonoo");  
%>  

<a href="process.jsp">visit</a>

process.jsp

Value is ${ sessionScope.user }  

download this example

EL Cookie Example

index.jsp

<h1>First JSP</h1>  
<%  
Cookie ck=new Cookie("name","abhishek");  
response.addCookie(ck);  
%>  
<a href="process.jsp">click</a>

process.jsp

Hello, ${cookie.name.value}

Precedence of Operators in JSP

Many operators have been given in the expression language. And their precedence is given below:

[] .

()

-(unary) not ! empty

* / div % mod

+ - (binary)

< <= > >= lt le gt ge

== != eq ne

&& and

'' or

?:

Reserve words in EL

Many Reserve words are there in the Expression Language that is given below:

lt

le

gt

ge

eq

ne

true

false

and

or

not

instanceof

div

mod

empty

null