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)
- Syntax of Expression Languages in JSP pages.
- Reserve words in EL
- JSP EL Implicit Objects
- JSP EL param Example
- EL applicationScope in JSP Example
- EL sessionScope Example in JSP
- Basic Operators in EL JSP
- Functions in JSP EL
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:
- $ {Expression}
- # {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:
- JSP Standard Tag Library Tutorial (JSTL), JSTL Tags
- JSP Directives: Page, Include & Taglib Directive
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 EL param Example:
Output:
EL applicationScope in JSP Example:
Output:
EL sessionScope Example in JSP:
Output:
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:
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.