How do you handle session attributes in Spring MVC?
Compare HttpSession, @SessionAttributes and @SessionAttribute in Spring MVC, with examples for multi-step forms, clearing state and session-scoped beans.
Spread Your Knowledge. Questions with answers, tutorials and articles, newest first.
Compare HttpSession, @SessionAttributes and @SessionAttribute in Spring MVC, with examples for multi-step forms, clearing state and session-scoped beans.
Use Pageable and Spring Data repositories to return pages, set sane size limits, sort safely and pick between Page, Slice and keyset scrolling.
Build a rate-limiting servlet filter in Spring with a fixed window and Bucket4j token buckets, returning 429 with Retry-After.
@RequestParam binds query and form parameters to controller method arguments. Learn required, defaultValue, Optional, lists and validation.
Cache-Control tells browsers and CDNs whether and how long to cache a response. Learn the key directives and the right policy for assets, HTML and APIs.
Combine Spring's cache abstraction with HTTP caching headers to cut database load and response time in a REST API, and learn how to evict stale entries safely.
@ResponseBody writes a controller's return value straight to the HTTP response, usually as JSON. See how it differs from views and @RestController.
Use ResponseEntity for one endpoint, a OncePerRequestFilter for every response, and ResponseBodyAdvice when the header depends on the returned body.
Content-Disposition controls inline display versus file download and the suggested file name. Learn syntax, Spring and Servlet examples and security tips.
Serve downloadable files in Spring MVC using ResponseEntity, Resource and HttpServletResponse, with correct headers and path traversal protection.
BindingResult collects binding and validation errors for a Spring MVC object. Declare it right after the @Valid parameter and check hasErrors() to handle failures.
Define a @Constraint annotation, write a ConstraintValidator and trigger it with @Valid to validate input in Spring MVC and Spring Boot.
@Valid triggers Bean Validation on controller parameters and nested objects. See setup, DTO examples, error handling and the @Validated difference.
Use @Valid with BindingResult, Jakarta constraint annotations and custom validators to check form and REST input in Spring MVC controllers.
Use Pageable for sorting and paging, query parameters for filters and JpaSpecificationExecutor to combine them into one safe, efficient database query.
@RequestBody tells Spring MVC to convert the HTTP request body into a Java object. See JSON binding, validation, error handling and common mistakes.
Compare URI, header, query parameter and media type versioning in Spring Boot, with code for each, native Spring 7 versioning and a deprecation plan.
Compare URI, header, parameter and media type versioning in Spring, see working controller code, and learn what built-in API versioning in Spring Framework 7 adds.
@RestController marks a Spring controller whose methods write return values to the response body. See a complete REST controller with validation and error handling.
@PathVariable binds a placeholder in a Spring URL mapping to a controller method parameter. Learn naming, conversion, optional variables and common errors.