SPRING CONCEPTS

HTTP redirect

Spring Concepts / HTTP redirect

A redirect tells the browser to request a different URL.

Understand the idea

sendRedirect produces a redirect response. The browser follows it with a new request, so old request attributes are gone. Post/Redirect/Get uses that new GET after a successful mutation, reducing accidental resubmission on refresh.

A concrete example

POST create
→ change state
→ 302 + Location
→ browser GET list

In the application

TodoServlet uses the session for one-time messages before redirecting to the list.

Build the destination with the context path. Request attributes are not transferred into the new GET.

Related concepts

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