Junior
What do you know about the JSP expression language, known as JSP Expression Language (EL)?
sobes.tech AI
Answer from AI
JSP Expression Language (EL) is a language of expressions used in JSP to access data of Java components (such as JavaBeans) and perform basic operations.
Main features:
- Access to properties: Allows retrieving property values of objects.
${user.name} - Access to collection elements: Allows retrieving elements of arrays and collections by index or key.
${users[0]} ${map['key']} - Arithmetic operations: Supports addition, subtraction, multiplication, and division.
${price * quantity} - Logical operations: Supports comparison (==, !=, <, >, <=, >=), logical AND (and, &&), OR (or, ||), NOT (not, !).
${user.age ge 18} - instanceof operation: Checks the type of an object.
${object instanceof 'java.lang.String'} - Ternary operator: Conditional expression in a single line.
${status == 'active' ? 'Active' : 'Inactive'} - Explicit and implicit objects: Access to objects such as
pageContext,request,session,application,param,paramValues,header,headerValues,cookie.
Table of implicit EL objects:
| Object | Description |
|---|---|
pageContext |
JSP PageContext |
pageScope |
Map of page-level attributes |
requestScope |
Map of request-level attributes |
sessionScope |
Map of session-level attributes |
applicationScope |
Map of application-level attributes |
param |
Map of request parameters (first value) |
paramValues |
Map of request parameters (all values) |
header |
Map of request HTTP headers (first value) |
headerValues |
Map of request HTTP headers (all values) |
cookie |
Map of Cookie objects |
initParam |
Map of servlet initialization parameters |
EL simplifies data access in JSP and reduces the use of scriptlets (<% %>), making pages more readable and maintainable. It is used in JSP 2.0 and above.