title: Spring MVC 3 ModelAndView: controller method to return several views
body: <p>my requirement is to return view according to the selected value (select form) </p>
  
  <p>view.jsp:</p>
  
  <pre><code>      &lt;form  method="post" action="/aaa"&gt;
                        &lt;select id="attr1" name="attr1"&gt;
  
                              &lt;option value="1"&gt;A&lt;/option&gt;
                              &lt;option value="2"&gt;B&lt;/option&gt;
  
                          &lt;/select&gt;
                    &lt;input type="submit" value="submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>if the value selected is A(1) is selected, view1 is the view to display, else view2 is displayed.  </p>
  
  <p>Controller method:</p>
  
  <pre><code>@RequestMapping(value = "/aaa", method = RequestMethod.POST)
  public ModelAndview methodName ( HttpServletRequest request,
          HttpServletResponse response){
  
     attribute=request.getParameter("attr1");
  
     if (attribute==1) return new ModelAndView("view1")
     else if (attribute==2) return new ModelAndView ("view2")
  
     }
  </code></pre>
  
  <p>How can I do it? 
  Thanks.</p>