title: Spring 3.0 MVC , Unable to register Home Controller , 404 Error
body: <p>I have configured hibernate &amp; Spring without any errors and my project is deploying, however I’m try to load my Home.jsp via a controller “HomeController” but I’m getting “Error :404 Resource not found…”: </p>
  
  <hr>
  
  <p>I have tried 3 different approaches:</p>
  
  <p><strong>Approach Number 1 (Not my ideal approach).</strong></p>
  
  <p>a)  Define a index.htm in welcome list (web.xml)</p>
  
  <p>b)  Map HomeController to “/index.htm” via annotations using @Controller @RequestMethod</p>
  
  <p>c)  HomeController returns view “Home” (WEB-INF/views/Home.jsp)</p>
  
  <hr>
  
  <p>Common project structure used for all 3 approaches:</p>
  
  <p><img src="https://i.stack.imgur.com/fwXbS.png" alt="enter image description here"></p>
  
  <hr>
  
  <p><strong>Web.xml:</strong></p>
  
  <pre><code>&lt;web-app metadata-complete="true" 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;yourmarketnet&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;yourmarketnet&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><strong>Yourmarketnet-spring.xml snippet:</strong></p>
  
  <pre><code>  &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"     
          p:prefix="/WEB-INF/views/" p:suffix=".jsp" p:viewClass="org.springframework.web.servlet.view.JstlView" /&gt;
  </code></pre>
  
  <p><strong>applicationContext.xml:</strong></p>
  
  <pre><code>&lt;!-- Activates various annotations to be detected in bean classes --&gt; 
      &lt;context:annotation-config /&gt;
      &lt;!-- Scans the classpath for annotated components that will be auto-registered as Spring beans.   For example @Controller and @Service. Make sure to set the correct base-package--&gt; 
      &lt;context:component-scan base-package="com.yourmarketnet.controller" /&gt;    
      &lt;!-- Configures the annotation-driven Spring MVC Controller programming model.  Note that, with Spring 3.0, this tag works in Servlet MVC only!  --&gt; 
      &lt;mvc:annotation-driven/&gt;
      &lt;!-- mapping of static resources--&gt;
      &lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt;
      &lt;import resource="hibernate-context.xml" /&gt;
  </code></pre>
  
  <p><strong>HomeController Class:</strong></p>
  
  <pre><code>package com.yourmarketnet.controller;
  @Controller  
  @RequestMapping("/index.htm") 
  public class HomeController {  
      public String requestHandler()
      { 
          return "Home"; 
      } 
  }   
  </code></pre>
  
  <p><strong>Result of Running application :</strong> </p>
  
  <p>Http Status 404 </p>
  
  <p>The requested resource () is not available.</p>
  
  <hr>
  
  <p><strong>Approach Number 2,  (Not my ideal approach)</strong></p>
  
  <p>a)  Create redirect.jsp , and define welcome list (web.xml)</p>
  
  <p>b)  Map HomeController to “ /HomeController” via annotations  using @Controller @RequestMethod</p>
  
  <p>c)  Have redirect.jsp “&lt;% response.sendRedirect("/HomeController");%>” to my HomeController</p>
  
  <p>d)  HomeController returns view “Home” (WEB-INF/views/Home.jsp)</p>
  
  <p><strong>Web.xml:</strong></p>
  
  <pre><code>&lt;web-app metadata-complete="true" 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;yourmarketnet&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;yourmarketnet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&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>Yourmarketnet-spring.xml snippet:</strong></p>
  
  <pre><code> &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"     
          p:prefix="/WEB-INF/views/" p:suffix=".jsp" p:viewClass="org.springframework.web.servlet.view.JstlView" /&gt;
   &lt;/beans&gt;
  </code></pre>
  
  <p><strong>applicationContext.xml snippet:</strong></p>
  
  <pre><code>&lt;!-- Activates various annotations to be detected in bean classes --&gt; 
      &lt;context:annotation-config /&gt;
      &lt;!-- Scans the classpath for annotated components that will be auto-registered as Spring beans.   For example @Controller and @Service. Make sure to set the correct base-package--&gt; 
      &lt;context:component-scan base-package="com.yourmarketnet.controller" /&gt;    
      &lt;!-- Configures the annotation-driven Spring MVC Controller programming model.  Note that, with Spring 3.0, this tag works in Servlet MVC only!  --&gt; 
      &lt;mvc:annotation-driven/&gt;
      &lt;!-- mapping of static resources--&gt;
      &lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt;
      &lt;import resource="hibernate-context.xml" /&gt;
  </code></pre>
  
  <p><strong>HomeController Class:</strong></p>
  
  <pre><code>package com.yourmarketnet.controller;
  @Controller  
  @RequestMapping("/HomeController") 
  public class HomeController {  
      public String requestHandler()
      { 
          return "Home"; 
      } 
  }
  </code></pre>
  
  <p><strong>Result of Running application :</strong> </p>
  
  <p>Http Status 404 /HomeController</p>
  
  <p>The requested resource (/HomeController) is not available.</p>
  
  <hr>
  
  <p><strong>Approach Number 3,  (If any off the above works its fine, however this is what I really want)</strong></p>
  
  <p>a)  Remove all welcome file tags from web.xml</p>
  
  <p>b)  MapDispatcher to “/”</p>
  
  <p>c)  Map HomeController to  “/HomeController” via annotations using @Controller @RequestMethod'</p>
  
  <p>d)  HomeController returns view “Home” (WEB-INF/views/Home.jsp)</p>
  
  <p><strong>Web.xml:</strong></p>
  
  <pre><code>&lt;web-app metadata-complete="true" 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;yourmarketnet&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;yourmarketnet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&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;/web-app&gt;
  </code></pre>
  
  <p>**Yourmarketnet-spring.xml snippet: **</p>
  
  <pre><code>   &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"     
          p:prefix="/WEB-INF/views/" p:suffix=".jsp" p:viewClass="org.springframework.web.servlet.view.JstlView" /&gt;
  </code></pre>
  
  <p><strong>applicationContext.xml snippet:</strong></p>
  
  <pre><code>&lt;!-- Activates various annotations to be detected in bean classes --&gt; 
      &lt;context:annotation-config /&gt;
      &lt;!-- Scans the classpath for annotated components that will be auto-registered as Spring beans.   For example @Controller and @Service. Make sure to set the correct base-package--&gt; 
      &lt;context:component-scan base-package="com.yourmarketnet.controller" /&gt;    
      &lt;!-- Configures the annotation-driven Spring MVC Controller programming model.  Note that, with Spring 3.0, this tag works in Servlet MVC only!  --&gt; 
      &lt;mvc:annotation-driven/&gt;
      &lt;!-- mapping of static resources--&gt;
      &lt;mvc:resources mapping="/resources/**" location="/resources/" /&gt;
      &lt;import resource="hibernate-context.xml" /&gt;
  </code></pre>
  
  <p><strong>HomeController Class:</strong></p>
  
  <pre><code>package com.yourmarketnet.controller;
  @Controller  
  @RequestMapping("/") 
  public class HomeController {
  
      public String requestHandler()
      { 
          return "Home"; 
      } 
  }   
  </code></pre>
  
  <p><strong>Apache Server log:</strong></p>
  
  <p>WARNING: No mapping found for HTTP request with URI [/yourmarketnet/] in DispatcherServlet with name 'yourmarketnet'</p>
  
  <p><strong>Result of Running application :</strong> </p>
  
  <p>Http Status 404 </p>
  
  <p>The requested resource () is not available.</p>
  
  <p>Please provide me with the correct code/tags in order to server my Home.jsp from HomeController without 404 Error, Thank you.</p>