I just want to add an important explanation concerning the response of @MattSenter.
The Servlet's dispatcher mechanism in Spring frameworks does the following behind the scenes :
When you add HttpServletResponse as an argument in your controller method as follows :
@RequestMapping
public String myController(@PathVariable someId, ModelMap map, HttpServletResponse response) {
// whatever the code here
return "myViewName";
}
It returns response (which is of type HttpServletResponse) without needing to write inside your method something like "return response". All is done behind the scenes! I know it's something that can be confusing for beginners !
If you are curious and you wonder how, please read the following :
When your controller method is called, Spring:
Injects the HttpServletResponse object automatically.
Lets you modify the response (e.g., set cookies, headers).
Spring takes your method's return value (if you have one) (e.g., ResponseEntity<TypeOfResponse>) and combines it with anything you've added to the HttpServletResponse.
Spring then writes the final response to the client automatically. You don't have to call response.send() or return response.
All of these mechanisms are called Inversion of Control (IoC) for Spring MVC and Spring Dispatcher Servlet's.