title: Redirect after POST method in spring MVC
body: <p>My problem is that I want to redirect to my index page without having to see the attributes appended in the URL.</p>
  
  <p>I found the solution to be <code>addFlashAttributes</code>, it doesn't append attributes in the URL but I can't see any message saved by this method.</p>
  
  <p><strong>Code:</strong></p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>@RequestMapping(value="/login",method = RequestMethod.POST)  
  public ModelAndView loginResult(HttpServletRequest req,
                                  HttpServletResponse res,
                                  RedirectAttributes redir) {
      if (uname.equals(inf.getUsername()) &amp; &amp;pwd.equals(inf.getPassword()) &amp;&amp; dept.equals(inf.getDept()))
      {
          req.getSession().setAttribute("uname",inf.getName());
          return new ModelAndView("employeeLoginResult", "message", message1); 
      }
      else if (uname.equals(inf2.getUsername()) &amp;&amp; pwd.equals(inf2.getPassword()) &amp;&amp; dept.equals(inf2.getDept()))
      {
          req.getSession().setAttribute("uname", inf2.getName());
          return new ModelAndView("adminLoginResult", "message", message2); 
      }
      else
      {
          ModelAndView modelAndView = new ModelAndView();
          modelAndView.setViewName("redirect:/index.jsp");
          redir.addFlashAttribute("message","Sorry Username Password Error");
          return modelAndView;
      }
  }
  </code></pre>
  
  <p>Right now I have hardcoded values for validation and would integrate the validation with DAO layer of database in the future. The <code>addFlashAttribute</code> does the work for me of not appending the message to the URL, but I also want to display the message on the index page.</p>
  
  <p><strong>Index page</strong></p>
  
  <pre><code>&lt;head&gt;&lt;tile&gt;index&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;b&gt;&lt;span class="heading"&gt;LOGIN USER&lt;/span&gt;&lt;/b&gt;
      &lt;div class="container"&gt;
          &lt;form action="login.html" method="Post"&gt;
              &lt;div class="form_style"&gt;
              &lt;input type="text" name="username" placeholder="Enter Username"/&gt;
              &lt;input type="password" name="pwd" placeholder="Enter password"/&gt;
              &lt;select name="dept"&gt;
                  &lt;option&gt;IT&lt;/option&gt;
                  &lt;option&gt;Admin&lt;/option&gt;
                  &lt;option&gt;HR&lt;/option&gt;
                  &lt;option&gt;Marketing&lt;/option&gt;
              &lt;/select&gt;
              &lt;input type="Submit" value="submit"&gt;
              &lt;p&gt;${message}&lt;/p&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>What am I doing wrong? Can anyone explain? </p>
  
  <p>Why is <code>${message}</code> not displaying the attribute?</p>
  
  <p>Any help is appreciated. Thanks for the same.</p>