SPRING CONCEPTS

Request / session attributes

Spring Concepts / Request / session attributes

Attributes are Java values stored by server-side code in a scope.

Understand the idea

Request attributes are available during one request and its forwards. Session attributes are available across requests associated with that session. They can hold Java objects rather than only strings. The Servlet chooses what data to expose to a view.

A concrete example

request.setAttribute("todos", store.list());
session.setAttribute("flash", "Todo saved");

In the application

The beginner Servlet forwards request attributes to JSP; the later Spring controller uses Model attributes.

Client request parameters are different. A redirect creates a new request, so old request attributes do not carry over.

Related concepts

Read the official documentation ↗
Java 21 · Spring Boot 4.1.1 · Edupoly