JSP Expression Language (EL)

SHARE & COMMENT :

Expression Language(EL) is to access application data stored in JavaBeans components.

The Syntax of EL in a Jsp is:

${expression}

General Example for EL

Let us create two files namely as expr.jsp and expprocess.jsp.

Listing 1:expr.jsp

<html>
<head>

<title>Expression Example</title>
</head>
<body><h3>welcome to javabeats</h3>

<%
session.setAttribute("abc","javabeats");
%>

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

</body>
</html>

This file is used to get input from user. We have used sessionscope object for printing the data that is saved in session scope using EL. The sessionScope object will been explained in next sections.

Listing 2:expprocess.jsp

<html>
<head>

<title>Insert title here</title>
</head>
<body>
Value is ${sessionScope.abc }

</body>
</html>

This file is a process file where in user sends request , which in turn prints the name of the user using EL. Here ${sessionScope.adc} is a expression Language(EL)tag.

Execute the jsp file expr.jsp in Eclipse by selecting Run As > Run On Server an output as below would be seen:
jsp_el1_demo

Now click on the link and the you would be take to the screen:

jsp_el2_demo

Basic Operator of EL

Expression language in JSP supports most of operators supported by Java.

Types of Operator:

  • Arithmetic operators
  • Relational Operators
  • Logical Operators
  • Empty Operators

Arithmetic operators

This table lists all the arithmetic operators supported by JSP EL.

Operator SymbolDescription
+Addition
-Unary operator or minus
/ and divDivision
*Multiplication
% and modRemainder

Relational Operator

This table lists all the relarional operators supported by JSP EL.

Operator SymbolDescription
= = and eqEquals
!= and neNot equals
< and ltLess than
> and gtGreater than
<= and leLess than or equal
>= and geGreater than or equal

Logical Operator

This table lists all the logical operators supported by JSP EL.

Operator SymbolDescription
&& and ANDand
|| and orOr
! and notnot

Implicit Object in JSP EL

JSP developers can directly use implicit objects in an EL Expression.

Implicit ObjectDescription
pageContextIt is used to manipulate page attributes and access object request, session etc
paramRequest parameter to a single string parameter value.
paramValuesRequest parameter to an array of values
HeaderRequest Header names to a single string header value
headerValuesRequest Header names to an array of values
pageScopeRequest page-scoped attribute names to the to their values
requestScopeRequest request-scoped attribute names to the to their values
sessionScopeRequest session-scoped attribute names to the to their values
applicationScopeRequest application-scoped attribute names to the to their values
cookieRequest cookie names to a single Cookie value
initParamContext initialization parameter names to their string parameter values

Previous Tutorial : Send Mail using JSP || Next Tutorial : Cookie Handling in JSP

Comments

comments

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Speak Your Mind

*

Close
Please support the site
By clicking any of these buttons you help our site to get better