JSP Expression Language

JSP introduced the concept of expression language (EL) in JSP 2.0 version. The purpose of expression language is to access and manipulate data easily without using any type of scriptlet.

Why Expression language?

Before JSP 2.0, scriptlets are used to handle the business logic. But it is difficult task for web designers to understand and code the java part in scriptlets. Hence, now expression language is used to overcome this difficulty. 

Syntax

This is the simple syntax of expression language.

${expression}

Expression Language Operator

JSP expression language provides an easy way to perform various arithmetic, relational, logical operations. These are some of the frequently used operators: -

  • Arithmetic operators – It contains various mathematical operators such as addition (+), subtraction (-), division (/ or div), module (% or mod), multiplication (*).
  • Logical operators – It contains operators like && (and), || (or).
  • Relational operators – It contains operators like < (less than), > (greater than), <= (less than or equal to), >= (greater than or equal to).

Example of JSP Expression Language Operator

This is a simple example of JSP operators that perform various mathematical operations between two numbers (10 & 5) directly.

Index.jsp

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h2>Arithmetic Operators : 10&5 </h2>
Addition :
${10+5}
<br>
Subtraction :
${10-5}
<br>
Multiplication :
${10*5}
<br>
Division :
${10/5}
<br>
<h2>Relational Operators : 10&5 </h2>
Equality Check (==) :
${10==5}
<br>
Non-Equality Check (!=) :
${10!=5}
<br>
Less number check (<) :
${10<5}
<br>
Greater number check (>) :
${10>5}
</body>
</html>
Output: