title: New to Spring unable to get controller working
body: <p>I am new to Spring and have looked at countless examples and cannot figure out this problem. The issue that I have is that when I click the link from my index.jsp page it does not forward to the hello.jsp page. I do not know why. I have spent 2 days looking up examples and trying countless examples trying to determine what the problem is to no avail. I am hoping you can tell me what the issue is. I am using NetBeans 7.2, Tomcat 7, JDK 7, Spring 3.2.1. The redirect.jsp works to get to the index.jsp page, but clicking the link on the index.jsp page gives me a 404 error.</p>
  
  <p>The way I understand it, the welcome-file is the redirect.jsp (not sure how this file is handled and why it is not gine through the dispatcher - because it is a jsp?). This redirects to an htm file. The dispatcher finds a url mapping that matches the index.htm and calls the indexController, which sends to the "index" view, which is "/WEB-INF/jsp/" + index + ".jsp".</p>
  
  <p>When Tomcat starts up I see the following messages:</p>
  
  <pre><code>Mapped URL path [/helloworld] onto handler 'helloWorldController'
  Mapped URL path [/helloworld/*] onto handler 'helloWorldController'
  Mapped URL path [/index.htm] onto handler 'indexController'
  </code></pre>
  
  <p>Clicking the link in the index.jsp gives the following warning message:</p>
  
  <pre><code>No mapping found for HTTP request with URI [/WTSpring3/hello.htm]
  </code></pre>
  
  <p>My web files are layed out as follows:</p>
  
  <pre><code>web
    WEB-INF
      jsp
        hello.jsp
        index.jsp
      applicationContext.xml
      dispatcher-servlet.xml
      web.xml
    redirect.jsp
  </code></pre>
  
  <p><strong>redirect.jsp</strong></p>
  
  <pre><code>&lt;% response.sendRedirect("index.htm"); %&gt;
  </code></pre>
  
  <p><strong>index.jsp</strong> (this is the one I can never get to work. I am not sure if I have the link incorrect of the Spring setup).</p>
  
  <pre><code>&lt;html&gt;&lt;body&gt;
  &lt;a href="hello.htm"&gt;Say Hello&lt;/a&gt;
  &lt;/body&gt;&lt;/html&gt;
  </code></pre>
  
  <p><strong>hello.jsp</strong></p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;${message}&lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>web.xml</strong>
  - note he url-pattern here is *.htm, which is what I use in my index.jsp.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="3.0" 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_3_0.xsd"&gt;
  
  &lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;/WEB-INF/applicationContext.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;servlet&gt;
      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;*.htm&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;session-config&gt;
      &lt;session-timeout&gt;
          30
      &lt;/session-timeout&gt;
  &lt;/session-config&gt;
  &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;redirect.jsp&lt;/welcome-file&gt;
  &lt;/welcome-file-list&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>dispatcher-servlet.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:p="http://www.springframework.org/schema/p"
     xmlns:aop="http://www.springframework.org/schema/aop"
     xmlns:tx="http://www.springframework.org/schema/tx"
     xmlns:context="http://www.springframework.org/schema/context"
  
     xsi:schemaLocation="http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
     http://www.springframework.org/schema/aop
     http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
     http://www.springframework.org/schema/tx
     http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
     http://www.springframework.org/schema/context
     http://www.springframework.org/schema/context/spring-context-3.2.xsd"&gt;
  
  &lt;bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping" /&gt;
  
  &lt;context:component-scan base-package="net.mvp.spring3.controller" /&gt;
  
  &lt;bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"&gt;
      &lt;property name="mappings"&gt;
          &lt;props&gt;
              &lt;prop key="index.htm"&gt;indexController&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver"
        p:prefix="/WEB-INF/jsp/"
        p:suffix=".jsp" /&gt;
  
  &lt;bean name="indexController"
        class="org.springframework.web.servlet.mvc.ParameterizableViewController"
        p:viewName="index" /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>HelloWorldController.java</strong></p>
  
  <pre><code> package net.mvp.spring3.controller;
  
      import org.springframework.stereotype.Controller;
      import org.springframework.web.bind.annotation.RequestMapping;
      import org.springframework.web.portlet.ModelAndView;
  
      @Controller
      public class HelloWorldController {
  
          @RequestMapping("hello")
          public ModelAndView helloWorld() {
              String message = "Hallo Asgard";
              return new ModelAndView("hello", "message", message);
          }
      }
  </code></pre>