title: Spring MVC 3.1 Redirect
body: <p>I am trying out Spring as a newbie and am running into following problem. I tried out redirection via a form. But when i click on the redirect submit button nothing happens, no error messages in the logs and the page just stays there. One of the answers available suggested adding new viewresolvers i did that, but the issue i am having remains. Also added a / after redirect:.  The index.jsp and final.jsp are in the WEB-INF Folder. The index.jsp with the bootstrap startup template is displayed correctly. But clicking on the redirectt button does nothing.  What am i doing wrong. Thanks.</p>
  
  <pre><code>package com.telenal.controller;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.ModelMap;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  
  @Controller
  @RequestMapping("/")
  public class BaseController {
  
  @RequestMapping(value = "/", method = RequestMethod.GET)
  public String welcome(ModelMap model) {
  
      model.addAttribute("message",
              "Maven Web Project + Spring 3 MVC - welcome()");
      System.out.println("returning index1");
      // Spring uses InternalResourceViewResolver and return back index.jsp
      return "index1";
  
  }
  
  @RequestMapping(value = "/redirect", method = RequestMethod.POST)
  public String welcome1(ModelMap model) {
  
      model.addAttribute("message",
              "Maven Web Project + Spring 3 MVC - welcome()");
  
      // Spring uses InternalResourceViewResolver and return back index.jsp
      return "redirect:/final";
  
  }
  
  @RequestMapping(value = "/welcome/{name}", method = RequestMethod.GET)
  public String welcomeName(@PathVariable String name, ModelMap model) {
  
      model.addAttribute("message", "Maven Web Project + Spring 3 MVC - "
              + name);
      return "index";
  
  }
  
  @RequestMapping(value = "/welcome", method = RequestMethod.GET)
  public String welcomeName1(@PathVariable String name, ModelMap model) {
  
      model.addAttribute("message", "Maven Web Project + Spring 3 MVC - "
              + name);
      return "redirect:index";
  
  }
  }
  </code></pre>
  
  <p>My web.xml</p>
  
  <pre><code>&lt;web-app xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        version="2.5"&gt;    
  
  &lt;display-name&gt;Counter Web Application&lt;/display-name&gt;
  
  &lt;servlet&gt;
      &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
      &lt;servlet-class&gt;
          org.springframework.web.servlet.DispatcherServlet
      &lt;/servlet-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;classpath*:appContext.xml&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;mvc-dispatcher&lt;/servlet-name&gt;
  
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;url-pattern&gt;*.jsp&lt;/url-pattern&gt;
      &lt;url-pattern&gt;*.js&lt;/url-pattern&gt;
      &lt;url-pattern&gt;*.png&lt;/url-pattern&gt;
      &lt;url-pattern&gt;*.css&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  &lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;/WEB-INF/mvc-dispatcher-servlet.xml&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;listener&gt;
      &lt;listener-class&gt;
          org.springframework.web.context.ContextLoaderListener
      &lt;/listener-class&gt;
  &lt;/listener&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>My index.jsp</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;
  &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
  &lt;meta name="description" content=""&gt;
  &lt;meta name="author" content=""&gt;
  &lt;link rel="icon" href="../../favicon.ico"&gt;
  
  &lt;title&gt;Starter Template for Bootstrap&lt;/title&gt;
  
  &lt;!-- Bootstrap core CSS --&gt;
  &lt;link href="dist/css/bootstrap.min.css" rel="stylesheet"&gt;
  
  &lt;!-- Custom styles for this template --&gt;
  &lt;link href="stylish-portfolio.css" rel="stylesheet"&gt;
  
  &lt;!-- Just for debugging purposes. Don't actually copy these 2 lines! --&gt;
  &lt;!--[if lt IE 9]&gt;&lt;script src="../../assets/js/ie8-responsive-file-warning.js"&gt;&lt;/script&gt;&lt;![endif]--&gt;
  &lt;script src="../../assets/js/ie-emulation-modes-warning.js"&gt;&lt;/script&gt;
  
  &lt;!-- IE10 viewport hack for Surface/desktop Windows 8 bug --&gt;
  &lt;script src="../../assets/js/ie10-viewport-bug-workaround.js"&gt;&lt;/script&gt;
  
  &lt;!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries --&gt;
  &lt;!--[if lt IE 9]&gt;
        &lt;script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"&gt;&lt;/script&gt;
        &lt;script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"&gt;&lt;/script&gt;
      &lt;![endif]--&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;div class="navbar navbar-inverse navbar-fixed-top" role="navigation"&gt;
      &lt;div class="container"&gt;
          &lt;div class="navbar-header"&gt;
              &lt;button type="button" class="navbar-toggle" data-toggle="collapse"
                  data-target=".navbar-collapse"&gt;
                  &lt;span class="sr-only"&gt;Toggle navigation&lt;/span&gt; &lt;span
                      class="icon-bar"&gt;&lt;/span&gt; &lt;span class="icon-bar"&gt;&lt;/span&gt; &lt;span
                      class="icon-bar"&gt;&lt;/span&gt;
              &lt;/button&gt;
              &lt;a class="navbar-brand" href="#"&gt;Project name&lt;/a&gt;
          &lt;/div&gt;
          &lt;div class="collapse navbar-collapse"&gt;
              &lt;ul class="nav navbar-nav"&gt;
                  &lt;li class="active"&gt;&lt;a href="#"&gt;Home&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="#about"&gt;About&lt;/a&gt;&lt;/li&gt;
                  &lt;li&gt;&lt;a href="#contact"&gt;Contact&lt;/a&gt;&lt;/li&gt;
              &lt;/ul&gt;
          &lt;/div&gt;
          &lt;!--/.nav-collapse --&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div class="container"&gt;
      &lt;br&gt;
      &lt;br&gt;
  
      &lt;div class="starter-template"&gt;
          &lt;h1&gt;Bootstrap starter template&lt;/h1&gt;
          &lt;p class="lead"&gt;
              Use this document as a way to quickly start any new   project.&lt;br&gt;
              All you get is this text and a mostly barebones HTML document.
          &lt;/p&gt;
      &lt;/div&gt;
  
  &lt;/div&gt;
  &lt;!-- /.container --&gt;
  &lt;h2&gt;Spring Page Redirection&lt;/h2&gt;
  &lt;p&gt;Click below button to redirect the result to new page&lt;/p&gt;
  &lt;form:form method="GET" action="/Guestbook/redirect"&gt;
  &lt;table&gt;
  &lt;tr&gt;
    &lt;td&gt;
     &lt;input type="submit" value="Redirectt Page"/&gt;
    &lt;/td&gt;
   &lt;/tr&gt;
  &lt;/table&gt;  
  &lt;/form:form&gt;
  
  
  &lt;!-- Bootstrap core JavaScript
  ================================================== --&gt;
  &lt;!-- Placed at the end of the document so the pages load faster --&gt;
  &lt;script
      src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;
  
  &lt;/script&gt;
  &lt;script src="dist/js/bootstrap.min.js"&gt;
  
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>my servelet.xml</p>
  
  <pre><code>    &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:mvc="http://www.springframework.org/schema/mvc"
      xsi:schemaLocation="
          http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd     
          http://www.springframework.org/schema/beans     
          http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context-3.1.xsd"&gt;
  
  
      &lt;mvc:default-servlet-handler/&gt;
      &lt;context:component-scan base-package="com.telenal.controller" /&gt;
  
      &lt;bean
  
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="prefix"&gt;
              &lt;value&gt;/WEB-INF/&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="suffix"&gt;
              &lt;value&gt;.jsp&lt;/value&gt;
          &lt;/property&gt; 
      &lt;/bean&gt;
      &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver"&gt;
      &lt;property name="basenames" value="views" /&gt;
      &lt;property name="order" value="1" /&gt;
  &lt;/bean&gt;   
  &lt;!-- UrlBasedViewResolver to Handle Redirects &amp; Forward --&gt;
  &lt;bean id="urlViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"&gt;
      &lt;property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" /&gt;
      &lt;property name="order" value="2" /&gt;
  &lt;/bean&gt;       
  &lt;/beans&gt;
  </code></pre>