Nearby lessons

13 of 30

JSP - EL Implicit Objects

📌 What You Will Learn
  • Know all 11 EL implicit objects
  • Use param, header, cookie, initParam objects
  • Use scope objects to access attributes in specific scopes

EL Implicit Objects give you access to request parameters, headers, cookies, scope attributes, and the page context — all through simple map-like syntax in EL expressions.

All 11 EL Implicit Objects

ObjectTypePurpose
pageScopeMapAttributes in page scope
requestScopeMapAttributes in request scope
sessionScopeMapAttributes in session scope
applicationScopeMapAttributes in application scope
paramMapRequest parameters (single values)
paramValuesMapRequest parameters (String[] arrays)
headerMapRequest headers (single values)
headerValuesMapRequest headers (String[] arrays)
cookieMapCookies associated with the request
initParamMapContext initialization parameters from web.xml
pageContextPageContextAccess all JSP implicit objects (the only non-Map)

Scope Objects

Use scope objects to retrieve attributes from a specific scope:

Example02
JCode Cell
1 
2${pageScope.p} → pageContext.getAttribute("p")
3${requestScope.p} → request.getAttribute("p")
4${sessionScope.p} → session.getAttribute("p")
5${applicationScope.p} → application.getAttribute("p")
6

Scope Search Order

When you write ${x} without a scope prefix, the container searches in order:

  1. Page scope
  2. Request scope
  3. Session scope
  4. Application scope

This is exactly the same as pageContext.findAttribute("x").

Example03
JCode Cell
1 
2<%
3 pageContext.setAttribute("p", "Pavan");
4 pageContext.setAttribute("p", "ravi", 2);
5 pageContext.setAttribute("p", "sunny", 3);
6 pageContext.setAttribute("p", "anushka", 4);
7%>
8${pageScope.p} → Pavan
9${requestScope.p} → ravi
10${sessionScope.p} → sunny
11${applicationScope.p} → anushka
12${p} → Pavan (first match: page scope)
13

param and paramValues

ObjectEquivalent Servlet MethodReturns
paramrequest.getParameter()Single String value
paramValuesrequest.getParameterValues()String[] array
Example04
JCode Cell
1 
2<%-- form: <input name="food" value="pizza"> <input name="food" value="pasta"> --%>
3${param.food} → pizza (first value only)
4${paramValues.food} → [Ljava.lang.String;@... (array toString)
5${paramValues.food[0]} → pizza
6${paramValues.food[1]} → pasta
7${paramValues.food[100]} → (blank — EL suppresses ArrayIndexOutOfBoundsException)
8

header and headerValues

Same as param/paramValues but for request headers:

Example05
JCode Cell
1 
2${header.accept} → the Accept header value
3${header.host} → the Host header value
4${headerValues.host[0]} → first Host header value
5

cookie

Access cookies from the request:

Example06
JCode Cell
1 
2${cookie.JSESSIONID.name} → JSESSIONID
3${cookie.JSESSIONID.value} → session-id-value
4

initParam

Access context parameters declared in web.xml:

Example07
JCode Cell
1 
2web.xml:
3<context-param>
4 <param-name>user</param-name>
5 <param-value>scott</param-value>
6</context-param>
7 
8JSP:
9${initParam.user} → scott
10${initParam.pwd} → tiger
11${initParam.mailId} → (blank — parameter not defined)
12

pageContext — Accessing JSP Objects

pageContext is the only non-Map EL implicit object. Use it to access JSP implicit objects:

Example08
JCode Cell
1 
2${pageContext.request.method} → GET
3${pageContext.session.id} → session-id
4${request.method} → invalid (no 'request' in EL)
5${session.id} → invalid (no 'session' in EL)
6
📝 Key Takeaways
  • EL has 11 implicit objects — most are Maps
  • pageContext is the only non-Map EL implicit object
  • EL handles null and ArrayIndexOutOfBoundsException gracefully

🧠 Test Your Knowledge

3 Questions
Progress: 0 / 3