SPRING CONCEPTS

Servlet Filter

Spring Concepts / Servlet Filter

A Filter runs around request handling and can decide whether processing continues.

Understand the idea

doFilter can set encoding, check a condition, and call chain.doFilter to reach the next filter or resource. Returning without that call prevents downstream handling. Filters can centralize cross-cutting request work.

A concrete example

request.setCharacterEncoding("UTF-8");
chain.doFilter(request, response);

In the application

RequestFilter sets UTF-8 before parameter decoding and rejects invalid todo form tokens.

Order matters. Setting request encoding after reading form parameters is too late for that decoding.

See it in a working stage

Related concepts

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