title: Spring MVC: Displaying of validation messages after redirect
body: <p>I have some very strange problem with displaying of error messages after redirect. I use RedirectAttributes to pass BindingResult object with error messages to a view, but this solution doesn't work.</p>
  
  <p>When I return just a view name withou redirect, everything works fine. </p>
  
  <p>Can someone give an advice, but without session usage?</p>
  
  <pre><code>@Controller
  public class UserRegistrationController {
  
      @Autowired
      private UserService userService;
  
      @RequestMapping(value="/registration", method=RequestMethod.GET)
      public ModelAndView registrationPage() {
          ModelAndView modelAndView = new ModelAndView("user-registration/registration-form");
          modelAndView.addObject("user", new User());
          return modelAndView;
      }
  
      @RequestMapping(value="/registration", method=RequestMethod.POST)
      public ModelAndView registerUser(@ModelAttribute @Valid User user, 
              BindingResult result,
              final RedirectAttributes redirectAttributes) {
          ModelAndView modelAndView = new ModelAndView("redirect:registration.html");
  
          User tempUser = userService.get(user.getEmail());
          Map&lt;String, String&gt; messages = new HashMap&lt;String, String&gt;();
  
          if (tempUser == null &amp;&amp; ! result.hasErrors()) {
              userService.save(user);
              messages.put("success", "message.user.success.register");
          } else {
              messages.put("error", "message.user.invalid.register");
              redirectAttributes.addFlashAttribute("user", user);
              redirectAttributes.addFlashAttribute("errors", result);
          }
  
          redirectAttributes.addFlashAttribute("messages", messages);
  
          return modelAndView;
  
      }
  
  }
  </code></pre>
  
  <p>And the view code:</p>
  
  <pre><code>&lt;p&gt;
  
      &lt;c:forEach var="message" items="${messages}"&gt;
          &lt;span class="${message.key}"&gt;&lt;spring:message code="${message.value}" /&gt;&lt;/span&gt;&lt;br /&gt;
      &lt;/c:forEach&gt;
  
  &lt;/p&gt;
  
  &lt;form:form method="POST" commandName="user" action="${pageContext.request.contextPath}/registration.html"&gt;
  &lt;table&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;spring:message code="user.registration.email" /&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:input path="email" /&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:errors cssClass="error" path="email" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;spring:message code="user.registration.password" /&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:password path="password" /&gt;&lt;/td&gt;
          &lt;td&gt;&lt;form:errors cssClass="error" path="password" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;input type="submit" /&gt;&lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
          &lt;td&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;/form:form&gt;
  </code></pre>