title: Passing model attribute during redirect in spring MVC and avoiding the same in URL
body: <p>My objective is to pass model attributes from controller to JSP page during a redirect and avoid the attribute being displayed in URL. The source code below is validating login from datastore using java data objects. </p>
  
  <p>Controller: </p>
  
  <pre><code>@Controller
  public class LoginController {
      int count;
      PersistenceManager pm = PMF.get().getPersistenceManager();
  
      //Instance of data class
          User user;
      ModelAndView modelAndView=new ModelAndView();
  
      @RequestMapping(value="/Login",method = RequestMethod.POST)
      public ModelAndView loginValidate(HttpServletRequest req){
  
          //Getting login values
          String uname=req.getParameter("nameLogin");
          String pswd1=req.getParameter("pswdLogin");
          count=0;
  
  
          user=new User();
  
          //Generating Query
          Query q = pm.newQuery(User.class);
          q.setFilter("userName == userNameParam");
          q.declareParameters("String userNameParam");
  
          try{
              List&lt;User&gt; results = (List&lt;User&gt;) q.execute(uname);  
              for (User u: results) {
  
                  String userName=u.getUserName();
  
                  if(userName.equals(uname)){
  
                      System.out.println(u.getPassword());
  
                      if(u.getPassword().equals(pswd1)){
                          count=count+1;
                          modelAndView.setViewName("redirect:welcome");
                          modelAndView.addObject("USERNAME",uname);
                          return modelAndView;
  
                      }
           //rest of the logic 
      }
  </code></pre>
  
  <p>JSP: </p>
  
  <pre><code> &lt;h1&gt;Welcome ${USERNAME} &lt;/h1&gt;
  </code></pre>
  
  <p>My current URL is <code>/welcome?USERNAME=robin</code><br>
  My goal is to display it as <code>/welcome</code> <br>
  Also, my page is supposed to display "Welcome robin" whereas it displays only Welcome.</p>