Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

JSP and Servlets
  • Servlets and JSP: What a Servlet Container Does and How a JSP Becomes a Servlet
  • Set Up Tomcat 11 and a Maven Web Project in IntelliJ IDEA
  • The Servlet Request Lifecycle: @WebServlet, web.xml, init, doGet and destroy
  • Servlet Request Parameters, and Forward vs Redirect
  • Run a Java Web App in Docker: Tomcat 11 With One Compose Command
  • Sessions, Cookies and Filters in Java Servlets: Log In Once, Stay Logged In
  • Servlets and JSP: What a Servlet Container Does and How a JSP Becomes a Servlet
  • JSP Scripting: Expressions, Scriptlets, Declarations, Comments and Includes
  • JavaBeans and JSP Scopes: Page, Request, Session and Application
  • JSP Expression Language Step by Step: ${...} for Beans, Maps, Lists, Params and Scopes
  • JSTL Core Tags: c:set, c:out, c:if, c:choose and c:forEach
  • JSTL Functions and Formatting: fn:length, fn:toUpperCase, fn:contains, fmt:formatNumber and fmt:formatDate
  • Maintaining and Migrating Legacy JSP With AI: Explain the Page, Refactor to a DAO, Servlet and JSTL, Then Move It to React
  • MVC and the Front Controller With Servlets and JSP
  • Forms With JSP and Servlets: Handle the POST and Validate on the Server
  • Mini App With Servlets and JSP: Login, Logout and a Shared Web Template
  • SQLite and a JDBC Connection Pool in a Java Web App
  • Users CRUD With Servlets and JSP, Part 1: Add and List Through a DAO
  • Users CRUD With Servlets and JSP, Part 2: Update and Delete
  1. Blog
  2. /
  3. JSP and Servlets
  4. /
  5. JSP

JSP Expression Language Step by Step: ${...} for Beans, Maps, Lists, Params and Scopes

Expression Language prints a value in a JSP with ${...} and no Java on the page. Read a Student bean, a price map, a tag list and ?city=Boston, run small checks, and see the order EL searches the scopes.

Chaand Sheikh

·27 November 2026·Updated 28 November 2026JSP

What you will learn

  • Print a bean property with ${student.name} instead of a Java cast
  • Read a map by key, a list by index and a URL parameter with param
  • Use EL operators: arithmetic, comparisons, and, empty and the ternary
  • Predict which scope ${message} reads when the name is set in several

Before you start

  • JavaBeans and JSP Scopes
  • MVC and the Front Controller With Servlets and JSP

Expression Language, EL for short, prints a value in a JSP with a small ${...} expression, with no Java code on the page. Think of a JSP as a form letter with blanks: "Hello, ____. Your order is ready." The page sits on the server, and when a request comes in the server fills every blank before the page leaves. An EL expression is how you write one blank.

The data: one servlet sets the attributes

A Student class holds name, age and active, plus a middleName that is never set, so it stays null. Remember that one. One servlet answers three URLs, loads the data and forwards to the page named by the URL:

package org.studyeasy.web;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

// the same data for every step; each URL shows it on its own page
@WebServlet({"/basics", "/access", "/operators"})
public class StepServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        req.setAttribute("student", new Student("Emma Clark", 21, true));
        req.setAttribute("prices", Map.of("Coffee", 2.75, "Green Tea", 3.5));
        req.setAttribute("tags", List.of("java", "sql", "html"));

        String step = req.getServletPath().substring(1);
        System.out.println(step + " -> " + step + ".jsp");
        req.getRequestDispatcher("/WEB-INF/views/" + step + ".jsp")
                .forward(req, resp);
    }
}
basics -> basics.jsp
access -> access.jsp
operators -> operators.jsp

getServletPath().substring(1) strips the slash, so /basics becomes the view name basics. That's all setup; the interesting part is in the JSPs.

Reading ${student.name}

The expression ${student.name} split into parts: ${ means start, student is the attribute name to find, .name is a property that calls getName(), and } means end. The browser receives Emma Clark. ${ student .name } start attribute to find calls getName() end Emma Clark The browser never sees the dollar sign; the server has already swapped it for the value.
An attribute name, a dot, a property name. The property goes through the getter.

EL doesn't touch the field. student.name calls getName(), and for a boolean the getter starts with is, so student.active calls isActive().

<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="org.studyeasy.web.Student" %>
<%-- STEP 1: the same value read twice, once with Java, once with EL --%>
<!DOCTYPE html>
<html>
<head><title>Basics</title></head>
<body>
<h1>Basics</h1>
<p>Java: <%= ((Student) request.getAttribute("student")).getName() %></p>
<p>EL: ${student.name}</p>
<p>Age: ${student.age}</p>
</body>
</html>
Basics
Java: Emma Clark
EL: Emma Clark
Age: 21

The Java line has to get the attribute from the request, cast it to Student and call the getter. The EL line gets the same value in a few characters.

Beans, maps, lists and the URL

<%@ page contentType="text/html;charset=UTF-8" %>
<%-- STEP 3: beans, maps, lists and URL parameters --%>
<!DOCTYPE html>
<html>
<head><title>Access</title></head>
<body>
<h1>Access</h1>
<p>Bean: ${student.name}</p>
<p>Map: ${prices['Green Tea']}</p>
<p>List: ${tags[0]}</p>
<p>URL parameter: ${param.city}</p>
<p>Missing: [${student.middleName}]</p>
</body>
</html>

Open /access?city=Boston:

Access
Bean: Emma Clark
Map: 3.5
List: java
URL parameter: Boston
Missing: []
  • A map takes the key in square brackets: prices['Green Tea']. Square brackets are needed here because the key has a space.
  • A list takes an index: tags[0] is the first element.
  • param.city reads the URL parameter. Remove ?city=Boston and that line just goes blank.
  • middleName is null, so nothing prints between the brackets, and there's no error either.

Small checks in the page

<%@ page contentType="text/html;charset=UTF-8" %>
<%-- STEP 4: small calculations and checks inside ${...} --%>
<!DOCTYPE html>
<html>
<head><title>Operators</title></head>
<body>
<h1>Operators</h1>
<p>Two coffees: ${prices.Coffee * 2}</p>
<p>Adult: ${student.age >= 18}</p>
<p>Can enrol: ${student.active and student.age >= 18}</p>
<p>No middle name: ${empty student.middleName}</p>
<p>Status: ${student.active ? 'Active' : 'Suspended'}</p>
</body>
</html>
Operators
Two coffees: 5.5
Adult: true
Can enrol: true
No middle name: true
Status: Active

prices.Coffee * 2 is 2.75 times 2. Comparisons give true or false, and and needs both sides. empty is true for null (and for empty strings and lists). The ternary ? : prints Active or Suspended. You don't need to memorise any of it; ask an AI assistant for the expression you want, then read it.

One name, three scopes

package org.studyeasy.web;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;

// one name, "message", in three scopes - with a different text in each
@WebServlet("/scopes")
public class ScopeServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        req.setAttribute("message", "Hello from the request");
        req.getSession().setAttribute("message", "Hello from the session");
        getServletContext().setAttribute("message", "Hello from the application");

        System.out.println("message in request, session, application");
        req.getRequestDispatcher("/WEB-INF/views/scopes.jsp").forward(req, resp);
    }
}

The name message now sits in three places: the request (this request only), the session (this browser) and the servlet context (the whole app). What does ${message} print?

<%@ page contentType="text/html;charset=UTF-8" %>
<%-- STEP 2: one name in three scopes --%>
<!DOCTYPE html>
<html>
<head><title>Scopes</title></head>
<body>
<h1>Scopes</h1>
<p>message: ${message}</p>
<p>sessionScope: ${sessionScope.message}</p>
<p>applicationScope: ${applicationScope.message}</p>
</body>
</html>
Scopes
message: Hello from the request
sessionScope: Hello from the session
applicationScope: Hello from the application

A plain name searches four scopes from the top: page, request, session, application. Page is empty, request has the value, so it stops there and session and application are never asked. To read a particular scope, name it: sessionScope.message, applicationScope.message.

Common mistakes

  • Spelling the property differently from the getter. ${student.Name} with a capital N fails, because there is no getName match for it. Write it the way the getter reads, minus get, with a small first letter.
  • Expecting an error for a missing value. EL prints nothing for null, which can hide a typo in an attribute name.
  • Setting the same name in several scopes and forgetting which one wins. The narrowest scope that has it wins.

Quick recap

ExpressionGives
${student.name}Emma Clark, through getName()
${message}the first match: page, request, session, application
${prices['Green Tea']}3.5, a map by key
${param.city}Boston, from the URL
${student.active ? 'Active' : 'Suspended'}Active

EL prints values. To decide and repeat without Java, add the tags in JSTL core tags.

Keep going in JSP and Servlets · 10 of 19

Previous
JavaBeans and JSP Scopes: Page, Request, Session and Application
Next post
JSTL Core Tags: c:set, c:out, c:if, c:choose and c:forEach
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE

Java 25, JSP, Hibernate, Spring Boot 4, REST APIs, React and Spring AI.View on Udemy ↗: FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE (paid course, opens in a new tab)

Related posts

Servlets and JSP: What a Servlet Container Does and How a JSP Becomes a Servlet

A JSP looks like HTML with a little Java, yet Tomcat runs it as a servlet. See what a servlet container does for each request, what the generated hello_jsp.java looks like, what a .war holds, and Tomcat vs TomEE.

JSP Scripting: Expressions, Scriptlets, Declarations, Comments and Includes

The JSP tags you'll read in older Java web apps: expressions, scriptlets, declarations, page imports, two kinds of comment, and the include directive versus the jsp:include action, each shown with what Tomcat turns it into.

JavaBeans and JSP Scopes: Page, Request, Session and Application

A Student bean filled from a form with jsp:useBean and setProperty, then one Counter class kept in four scopes. Three visits, two browsers and an include page show exactly who sees which number.

JSTL Core Tags: c:set, c:out, c:if, c:choose and c:forEach

Five JSTL core tags let a JSP decide and repeat with no Java on the page. Add the jars to pom.xml, then use c:set, c:out (and see why it is safer than plain EL), c:if, c:choose and c:forEach on three orders.

On this page

  • The data: one servlet sets the attributes
  • Reading ${student.name}
  • Beans, maps, lists and the URL
  • Small checks in the page
  • One name, three scopes
  • Common mistakes
  • Quick recap
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE

Java 25, JSP, Hibernate, Spring Boot 4, REST APIs, React and Spring AI.View on Udemy ↗: FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact us
Legal
Terms of UsePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.