SP EL
SP EL
Example:
1. JSP EL: JSP(Java Server Page) uses JSP EL to evaluate the objects and properties like request,
session, application etc. and their parameters and attributes.
2. Struts2.x -> OGNL: From struts 2.x version onwards struts framework uses OGNL to evaluate
the objects and their properties like Value Stack, CentralContext, request, application etc.
3. JBoss EL: To evaluate the objects and their properties which are related to JBoss
implementations.
4. SpEL: To evaluate Spring Bean Objects and their properties in Spring Application.
➢ It is an Expression Language.
➢ It has provided simplified syntax to manipulate object and their properties during the
runtime of the application.
➢ In Spring Framework, SpEL is introduced in Spring 3.x with a separate module i.e., Spring
Expression.
➢ You need spring-expression-<version>.jar file in your classpath to work with SpEL.
To prepare and Evaluate Expressions in SpEL, Spring has provided very good Predefined Library in
the form of "org.springframework.exprssion" package.
In SpEL, Expression object can represent single Expression. To represent Expression, Spring has
provided a predefined interface in the form of "org.springframework.expression.Expression". For
Expression interface Spring has provided a predefined implementation class in the form of
"org.springframework.expression.spel.standard.SpelExpression".
To prepare expression and to get Expression object we have to use the following method from
ExpressionParser.
To calculate & get expression result we have to use the following method from Expression.
Test.java
CalculatorBean.java
@Setter
@Getter
public class CalculatorBean {
}
Test.java
// Approach 1
Expression expr1 = parser.parseExpression("num1");
expr1.setValue(context, 10);
// Approach 2
Expression expr2 = parser.parseExpression("num2 = 20");
expr2.getValue(context);
SpEL features:
1. Expression
2. Operators
3. Variables
4. Method Invocations
5. Collections