Spring MVC 404 not found error
<p>I am trying to run a project in Spring MVC. Here is the code</p>

<p>index.jsp</p>

<pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
&lt;%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %&gt;
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd"&gt;

&lt;html&gt;
    &lt;head&gt;
        &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
        &lt;title&gt;Welcome to Spring Web MVC project&lt;/title&gt;
    &lt;/head&gt;

    &lt;body&gt;
        &lt;h1&gt;Spring 3 Register!&lt;/h1&gt;
        &lt;a href="register.htm"&gt;click&lt;/a&gt;
        &lt;form:form action="${pageContext.request.contextPath}/register.htm" method="POST" modelAttribute="userForm"&gt;
            &lt;table&gt;
                &lt;tr&gt;
                    &lt;td colspan="2" align="center"&gt;Spring MVC Form Demo - Registration&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;User Name&lt;/td&gt;
                    &lt;td&gt;&lt;form:input path="username" /&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;Password&lt;/td&gt;
                    &lt;td&gt;&lt;form:password path="password" /&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;Email&lt;/td&gt;
                    &lt;td&gt;&lt;form:input path="email" /&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;BirthDate (mm/dd/yyyy)&lt;/td&gt;
                    &lt;td&gt;&lt;form:input path="birthDate" /&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td&gt;Profession&lt;/td&gt;
                    &lt;td&gt;&lt;form:select path="profession" items="${professionList}" /&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;td colspan="2" align="center"&gt;&lt;input type="submit" value="Register" /&gt;&lt;/td&gt;
                &lt;/tr&gt;

            &lt;/table&gt;
        &lt;/form:form&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>RegistrationController.java</p>

<pre><code>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package RegisterInfo;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Harshit Shrivastava
 */
import RegisterInfo.model.User;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.ui.Model;

@Controller
@RequestMapping(value = "/register")
public class RegistrationController {

    @RequestMapping(method = RequestMethod.GET)
    public String viewRegistration(Model model)
    {
        User userForm = new User();
                model.addAttribute("userForm", new User());

                /*List&lt;String&gt; professionList = new ArrayList();
                professionList.add("Developer");
                professionList.add("Designer");
                professionList.add("IT Manager");
                model.put("professionList", professionList);*/
        return "index";
    }

    @RequestMapping(method = RequestMethod.POST)
    public String processRegistration(@ModelAttribute("userForm") User user, Map&lt;String, Object&gt; model)
    {       
        System.out.println("Username : " + user.getUserName());
        model.put("userForm", new User());
        return "index";
    }
}
</code></pre>

<p>User.java</p>

<pre><code>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package RegisterInfo.model;

/**
 *
 * @author Harshit Shrivastava
 */
import java.util.Date;

public class User {
    private String username;
    private String password;
    private String email;
    private Date birthDate;
    private String profession;

    public String getUserName()
    {
        return username;
    }
    public void setUserName(String username)
    {
        this.username = username;
    }
        public String getPassword()
    {
        return password;
    }
    public void setPassword(String password)
    {
        this.password = password;
    }
        public String getEmail()
    {
        return email;
    }
    public void setEmail(String email)
    {
        this.email = email;
    }
        public Date getBirthDate()
    {
        return birthDate;
    }
    public void setBirthDate(Date birthDate)
    {
        this.birthDate = birthDate;
    }
        public String getProfession()
    {
        return profession;
    }
    public void setProfession(String profession)
    {
        this.profession = profession;
    }
}
</code></pre>

<p>web.xml</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/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;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;index.htm&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
&lt;/web-app&gt;
</code></pre>

<p>dispatcher-servlet.xml</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"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-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/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd "&gt;

    &lt;bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/&gt;

    &lt;context:component-scan base-package="SpringRegister" /&gt;
    &lt;mvc:annotation-driven /&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>Project Structure :</p>

<p><a href="https://i.stack.imgur.com/afO1Y.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/afO1Y.jpg" alt="enter image description here"></a></p>

<p>In the above program, I am always getting the <code>404 not found status</code>. I tried</p>

<p><a href="http://localhost:8080/RegisterInfoMaven/index" rel="nofollow noreferrer">http://localhost:8080/RegisterInfoMaven/index</a></p>

<p><a href="http://localhost:8080/RegisterInfoMaven/index.htm" rel="nofollow noreferrer">http://localhost:8080/RegisterInfoMaven/index.htm</a></p>

<p>both not working.</p>

<p>When I remove web.xml &amp; dispatcher-servlet.xml from the project, then <code>http://localhost:8080/RegisterInfoMaven/index.jsp</code> loads fine, but as I put <code>web.xml &amp; dispatcher-servlet.xml</code>, then again it starts giving <code>404 not found</code> error.</p>

<p>What is wrong with <code>web.xml &amp; dispatcher-servlet.xml</code> files ?</p>