title: Spring MVC - How Return View To Correct Context Root
body: <p>My spring mvc application was built and deployed on root url "/" using glassfish server.</p>
  
  <p><a href="http://mydomain/" rel="nofollow">http://mydomain/</a></p>
  
  <p>Now I want to deploy a new version using other context path like "v2/"</p>
  
  <p><a href="http://mydomain/v2" rel="nofollow">http://mydomain/v2</a></p>
  
  <p>But when I run using a non-root path the controller try to return to "/" not to "v2"</p>
  
  <p>Example: </p>
  
  <ul>
  <li>Access <a href="http://mydomain/v2/login" rel="nofollow">http://mydomain/v2/login</a></li>
  <li>When I execute the authentication the controller send me to: <a href="http://mydomain/home" rel="nofollow">http://mydomain/home</a></li>
  <li>Should be: <a href="http://mydomain/v2/home" rel="nofollow">http://mydomain/v2/home</a></li>
  </ul>
  
  <p>Here is my controller method:</p>
  
  <pre><code>@RequestMapping(value = "/admin/home", method = RequestMethod.GET)
      public ModelAndView adminOperationsPage() {
          ModelAndView model = new ModelAndView();
          model.setViewName("/admin/home");
          return model;
      }
  </code></pre>
  
  <p>My viewResolver:</p>
  
  <pre><code>@Bean
      public InternalResourceViewResolver viewResolver() {
          InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
          viewResolver.setViewClass(JstlView.class);
          viewResolver.setPrefix("/WEB-INF/pages/");
          viewResolver.setSuffix(".jsp");
          return viewResolver;
      }
  </code></pre>
  
  <p>How can I take into account the Context Root "v2" on returning the view?</p>
  
  <p><a href="http://mydomain/v2/home" rel="nofollow">http://mydomain/v2/home</a>
  instead of 
  <a href="http://mydomain/home" rel="nofollow">http://mydomain/home</a></p>