Expression Language(EL)
Expression language (EL) has been introduced in JSP 2.0. The main purpose of it to simplify the process of accessing data from bean properties and from implicit objects. EL includes arithmetic, relational and logical operators too.
${expression}
whatever present inside braces gets evaluated at runtime and being sent to the output stream.
<html> <head> <title>Expression language example1</title> </head> <body>${1<2}${1+2+3}</body> </html>
Implicit Objects in JSP
JSP Implicit Objects are the Java objects that the JSP Container makes available to developers in each page and developer can call them directly without being explicitly declared. JSP Implicit Objects are also called pre-defined variables.
Following are the JSP implicit object
Implicit Object | Description |
request | The HttpServletRequest object associated with the request. |
response | The HttpServletRequest object associated with the response that is sent back to the browser. |
out | The JspWriter object associated with the output stream of the response. |
session | The HttpSession object associated with the session for the given user of request. |
application | The ServletContext object for the web application. |
config | The ServletConfig object associated with the servlet for current JSP page. |
pageContext | The PageContext object that encapsulates the enviroment of a single request for this current JSP page |
page | The page variable is equivalent to this variable of Java programming language. |
exception | The exception object represents the Throwable object that was thrown by some other JSP page. |
download the example:
EL implicit objects
JSP Expression Language provides many implicit objects that we can use to get attributes from different scopes and parameter values. The list is given below.
JSP EL Implicit Objects | Type | Description |
pageScope | Map | A map that contains the attributes set with page scope. |
requestScope | Map | Used to get the attribute value with request scope. |
sessionScope | Map | Used to get the attribute value with session scope. |
applicationScope | Map | Used to get the attributes value from application scope. |
param | Map | Used to get the request parameter value, returns a single value |
paramValues | Map | Used to get the request param values in an array, useful when request parameter contain multiple values. |
header | Map | Used to get request header information. |
headerValues | Map | Used to get header values in an array. |
cookie | Map | Used to get the cookie value in the JSP |
initParam | Map | Used to get the context initparams, we can’t use it for servlet initparams |
pageContext | pageContext | Same as JSP implicit pageContext object, used to get the request, session references etc. example usage is getting request HTTP Method name. |
0 responses on "3.4 Expression Language(EL)"