el in java – JSP Expression Language (EL) | Definition, Syntax, JSP EL Implicit Objects with Examples

el in java: The major aim of Expression Language (EL) is to explain the way of accessibility of the data stored in the Java bean component and other objects like request, session, and application, etc. Learn more about JSP EL like definition, syntax, operators, implicit objects, etc. from this ultimate tutorial.

This Tutorial of JSP Expression Language (EL) includes: 

JSP Expression Language (EL)

jsp $ expression: In JSP standard action and custom, action tags reduce java code from a JSP page. The main aim of the JSP expression language is to analyze the accessibility of data stored in the java bean component. It is also provided to reduces the java code from a JSP page in some areas. With the Expression language, we can reduce the java code in the following areas.

  • Reading Request parameter,
  • Reading cookies,
  • Reading attributes,
  • Accessing bean business method, etc.

The Expression Language is still determined within the JSP 2.1 specification. It now has its own independent specification document. The addition of the EL to the JSP technology gives much of the writing of script-less JSP pages. These pages can use EL expression but can’t use java scriptlets, java expressions, or java declaration elements.

Syntax of Expression Languages in JSP pages.

There are two constructs to define EL Expression. They are as follows:

  1. $ {Expression}
  2. # {Expression}

An EL Expression that is evaluated immediately is represented in JSP with the syntax $ { }.

An EL expression whose evaluation is deferred is represented with the syntax # { }.

Do Check:

Reserve words in EL

Here is the table where you can see several reserve words in the Expression Language. They are as such:

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

JSP EL Implicit Objects

There are some implicit objects that can be presented in the EL. These objects permit access to any variables, which are included in the appropriate JSP Scopes.

The implicit objects cover page Scope, request Scope, session Scope, and Application Scope. All these scope objects discussed here are nothing but Maps that map the respective scope attributes names to their values.

The following table summarized the available implicit objects:

JSP Expression Language (EL) 1

JSP EL param Example:

JSP Expression Language (EL) 2

JSP Expression Language (EL) 3

Output:

JSP Expression Language (EL) 4

JSP Expression Language (EL) 5

EL applicationScope in JSP Example:

JSP Expression Language (EL) 6

JSP Expression Language (EL) 7

Output:

JSP Expression Language (EL) 8

JSP Expression Language (EL) 9

EL sessionScope Example in JSP:

JSP Expression Language (EL) 10

JSP Expression Language (EL) 11

JSP Expression Language (EL) 12

Output:

JSP Expression Language (EL) 13

JSP Expression Language (EL) 14

JSP Expression Language (EL) 15

Basic Operators in EL JSP

JSP Expression Language implements the support for any type of relational, logical, or arithmetic operator, which you will require to perform. Revive, all results will be boolean values.

In order to guide you on how to use these operators, we have presented the following table:

JSP Expression Language (EL) 16

Functions in JSP EL

JSP Expression Language lets you to make use of the functions in expressions also. These EL Functions are defined in the custom tag libraries. One of the function has the following syntax:

${ns:func(param1, param2, ...)}

Parameters

Where,

  • ns is the function namespace,
  • func is the name of the function,
  • param1 is the first parameter value.

For instance, the function fn:length, is the part of the JSTL Library. And the function can be utilized as follows to get the string length.

${fn:length("Get my length")}

In order to apply any tag library, you need to install that library on your server and should involve the library in your JSP with the help of the <taglib> directive as discussed in the JSTL tutorial.