Tutorials Logic, IN +91 8092939553 info@tutorialslogic.com
FAQs Support
Navigation
Home About Us Contact Us Blogs FAQs
Tutorials
All Tutorials
Services
Academic Projects Resume Writing Interview Questions Website Development
Compiler Tutorials

JSP Expression Language (EL)

What is Expression Language?

Expression Language (EL) was introduced in JSP 2.0 to simplify access to data stored in JavaBeans, request parameters, session attributes, and other objects. EL expressions use the syntax ${expression} and can be used directly in HTML without scriptlets.

EL makes JSP pages cleaner and easier to maintain by eliminating verbose Java code like <%= (String) session.getAttribute("user") %> and replacing it with ${sessionScope.user}.

EL Implicit Objects

EL ObjectTypeDescription
paramMap<String,String>Request parameters (single value)
paramValuesMap<String,String[]>Request parameters (multiple values)
headerMap<String,String>HTTP request headers
headerValuesMap<String,String[]>HTTP headers (multiple values)
cookieMap<String,Cookie>Cookies from the request
pageScopeMapPage-scoped attributes
requestScopeMapRequest-scoped attributes
sessionScopeMapSession-scoped attributes
applicationScopeMapApplication-scoped attributes
initParamMapContext init parameters from web.xml
pageContextPageContextAccess to JSP page context
EL Syntax and Implicit Objects
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%
    // Set attributes in different scopes
    request.setAttribute("message", "Hello from Request!");
    session.setAttribute("username", "Alice");
    session.setAttribute("age", 25);
    application.setAttribute("appVersion", "2.0");
%>
<html><body>

<h3>Accessing Scoped Attributes</h3>
<p>Request: ${requestScope.message}</p>
<p>Session username: ${sessionScope.username}</p>
<p>Session age: ${sessionScope.age}</p>
<p>App version: ${applicationScope.appVersion}</p>

<%-- EL searches all scopes automatically (page, request, session, app) --%>
<p>Auto-search: ${username}</p>

<h3>Request Parameters</h3>
<p>Name param: ${param.name}</p>
<p>Age param: ${param.age}</p>

<h3>Headers and Cookies</h3>
<p>User-Agent: ${header['User-Agent']}</p>
<p>Cookie value: ${cookie.JSESSIONID.value}</p>

<h3>pageContext</h3>
<p>Context path: ${pageContext.request.contextPath}</p>
<p>Server name: ${pageContext.request.serverName}</p>

</body></html>

EL Operators

EL supports arithmetic, relational, logical, and the empty operator:

EL Operators
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<html><body>

<h3>Arithmetic Operators</h3>
<p>10 + 5 = ${10 + 5}</p>
<p>10 - 3 = ${10 - 3}</p>
<p>4 * 3 = ${4 * 3}</p>
<p>10 / 3 = ${10 / 3}</p>
<p>10 mod 3 = ${10 mod 3}</p>

<h3>Relational Operators</h3>
<p>5 == 5: ${5 == 5}</p>
<p>5 != 3: ${5 != 3}</p>
<p>10 > 5: ${10 gt 5}</p>
<p>3 < 7: ${3 lt 7}</p>
<p>5 >= 5: ${5 ge 5}</p>

<h3>Logical Operators</h3>
<p>true && false: ${true and false}</p>
<p>true || false: ${true or false}</p>
<p>!true: ${not true}</p>

<h3>Empty Operator</h3>
<p>Is null empty: ${empty null}</p>
<p>Is "" empty: ${empty ""}</p>
<p>Is "hello" empty: ${empty "hello"}</p>

<h3>Ternary / Conditional</h3>
<p>${param.age gt 18 ? "Adult" : "Minor"}</p>

</body></html>

Ready to Level Up Your Skills?

Explore 500+ free tutorials across 20+ languages and frameworks.