Expression Language (EL) in JSP by R4R Team

Expression Language (EL) in JSP:

The Expression Language (EL) simplifies the accessibility of data stored in the Java Bean component, and other objects like request, session, application etc.

There are many implicit objects, operators and reserve words in EL.
Precedence of Operators in EL:

There are many operators that have been provided in the Expression Language. Their precedence are as follows:

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

Reserve words in EL

There are many reserve words in the Expression Language. They are as follows:

lt le gt ge eq
ne true false and or
not instanceof div mod empty, null

It is the newly added feature in JSP technology version 2.0.
Syntax for Expression Language (EL)

${ expression }
Implicit Objects in Expression Language (EL)

There are many implicit objects in the Expression Language. They are as follows:

Implicit Objects Usage in EL:

param: it maps the request parameter to the single value
paramValues: it maps the request parameter to an array of values
pageScope: it maps the given attribute name with the value set in the page scope
requestScope: it maps the given attribute name with the value set in the request scope
sessionScope: it maps the given attribute name with the value set in the session scope
applicationScope: it maps the given attribute name with the value set in the application scope
header it maps the request header name to the single value
headerValues: it maps the request header name to an array of values
cookie it maps the given cookie name to the cookie value
initParam: it maps the initialization parameter
pageContext: it provides access to many objects request, session etc.
Simple example of Expression Language that prints the name of the user

In this example, we have created two files index.jsp and process.jsp. The index.jsp file gets input from the user and sends the request to the process.jsp which in turn prints the name of the user 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 }

Example: Expression Language that prints the value set in the session scope

In this example, we printing the data stored in the session scope using EL. For this purpose, we have used sessionScope object.

index.jsp:

<h3>welcome to index page</h3>

<%

session.setAttribute("user","alok");

%>

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

process.jsp

Value is ${ sessionScope.user }


Leave a Comment:
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!