close

Filter

loading table of contents...

Content Application Developer Manual / Version 2304

Table Of Contents
Preserving attributes in a redirect

Sometimes it is necessary to display status information (a confirmation message, for instance) as result of a POST handler. Spring MVC provides the concept of "Flash Attributes": Attributes that can be passed to the handler receiving a redirected request, for example:

public ModelAndView handleRequest(..., RedirectAttributes redirectAttributes) {

  // handle request

  redirectAttributes.addFlashAttribute(
        "status",
        "Everything is fine.");

  // send redirect using
  // HandlerHelper#redirectTo() or
  // a org.springframework.web.servlet.view.RedirectView
}

Also, see this post on Tikal.com.

Note

Note

Because of SPR-10516 any beans added as objects to ModelAndView are converted to Strings (and might require adding a converter to bindingConverters bean (see Section 4.3.1, “Handling Requests”) as soon as request handler specifies RedirectAttributes as parameter (and only then). This might prevent link handlers to be found by bean type. In order to work around this issue it is recommended to use HandlerHelper#redirectBuilder(bean) and specify the redirectAttributes which as a result when building the model and view will receive the model bean in addition to ModelAndView.

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.