title: Spring Mapping Url to Controller and View
body: <p>I have the standard Spring 4.x files in Netbeans 8.0.2. I added a controller, <code>RegisterController.java</code> in the <code>controllers</code>-package. I also added one model, a <code>User</code>, with some basic information about the user. Next I made 2 <code>.jsp</code> files, <code>Registration.jsp</code> and <code>RegistrationSuccess.jsp</code>.</p>
  
  <p>Here is my <strong>RegisterController</strong>:</p>
  
  <pre><code>@Controller
  @RequestMapping(value="/register")
  public class RegisterController {
      @RequestMapping(method=RequestMethod.GET)
      public String viewRegistration(Model model){
          User user = new User();
          model.addAttribute("userForm", user);
  
          List&lt;String&gt; professionList = new ArrayList&lt;&gt;();
          professionList.add("Developer");
          professionList.add("Designer");
          professionList.add("IT Manager");
          model.addAttribute("professionList", professionList);
  
          return "Registration";
      }
  
      @RequestMapping(method=RequestMethod.POST)
      public String processRegistration(@ModelAttribute("userForm") User user, Map&lt;String, Object&gt; Model){
          System.out.println("username: " + user.getUsername());
          System.out.println("password: " + user.getPassword());
          System.out.println("email: " + user.getEmail());
          System.out.println("birth date: " + user.getBirthDate());
          System.out.println("profession: " + user.getProfession());
  
          return "RegistrationSuccess";
      }
  }
  </code></pre>
  
  <p>Now, going to <code>myProject/register</code> results in a 404. I am confused how Spring manages the routing though. There is a <strong>web.xml</strong> looking like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.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;2&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>What I <em>think</em> this means is every url with <code>*.htm</code> goes to the <strong>dispatcher-servlet</strong>:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  &lt;!-- was: &lt;?xml version="1.0" encoding="UTF-8"?&gt; --&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"
         xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd"&gt;
  
      &lt;bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/&gt;
  
      &lt;!--
      Most controllers will use the ControllerClassNameHandlerMapping above, but
      for the index controller we are using ParameterizableViewController, so we must
      define an explicit mapping for it.
      --&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;!--
      The index controller.
      --&gt;
      &lt;bean name="indexController"
            class="org.springframework.web.servlet.mvc.ParameterizableViewController"
            p:viewName="index" /&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>But where do I need to insert some entries to let my RegisterController do work?</p>