title: How to fix "HTTP Status 404" Spring MVC
body: <p>I have a problem with my Spring web application: it shows Apache Tomcat/4.0.6 - HTTP Status 404 - /spring-mvc-example/ (The requested resource (/spring-mvc-example/) is not available.) I'm going crazy with this error and I don't know what to do.
  I'm using STS.
  Thank you for your help!
  This is how the folders are organized.
   <a href="https://i.stack.imgur.com/ded48.png" rel="nofollow noreferrer">https://i.stack.imgur.com/ded48.png</a></p>
  
  <p>web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
  xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
  http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" 
  version="4.0"&gt;
  &lt;display-name&gt;spring-mvc-example&lt;/display-name&gt;
  &lt;welcome-file-list&gt;
  &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
  &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
  &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
  &lt;welcome-file&gt;default.html&lt;/welcome-file&gt;
  &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt;
  &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;
  &lt;/welcome-file-list&gt;
  &lt;display-name&gt;spring-mvc-example&lt;/display-name&gt;
  
  &lt;!-- Add Spring MVC DispatcherServlet as front controller --&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;spring&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;/WEB-INF/spring-servlet.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;spring&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt; 
  &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  spring-servlet.xml
  &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/mvc" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xmlns:beans="http://www.springframework.org/schema/beans"
  xmlns:context="http://www.springframework.org/schema/context"
  xsi:schemaLocation="http://www.springframework.org/schema/mvc 
  http://www.springframework.org/schema/mvc/spring-mvc.xsd
      http://www.springframework.org/schema/beans 
  http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/context 
  http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
  &lt;!-- DispatcherServlet Context: defines this servlet's request-processing 
      infrastructure --&gt;
  
  &lt;!-- Enables the Spring MVC @Controller programming model --&gt;
  &lt;annotation-driven /&gt;
  &lt;context:component-scan base-package="com.spring" /&gt;
  
  &lt;!-- Resolves views selected for rendering by @Controllers to .jsp resources 
      in the /WEB-INF/views directory --&gt;
  &lt;beans:bean
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;beans:property name="prefix" value="/WEB-INF/views/" /&gt;
      &lt;beans:property name="suffix" value=".jsp" /&gt;
  &lt;/beans:bean&gt;
  </code></pre>
  
  <p></p>
  
  <p>pom.xml</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
  http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;groupId&gt;spring-mvc-example&lt;/groupId&gt;
  &lt;artifactId&gt;spring-mvc-example&lt;/artifactId&gt;
  &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  &lt;name&gt;Spring MVC Example&lt;/name&gt;
  &lt;description&gt;Picco esempio&lt;/description&gt;
  &lt;!-- Add Spring Web and MVC dependencies --&gt;
  &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
          &lt;version&gt;4.3.9.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
          &lt;version&gt;4.3.9.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;!-- Servlet --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
          &lt;version&gt;2.5&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet.jsp&lt;/groupId&gt;
          &lt;artifactId&gt;jsp-api&lt;/artifactId&gt;
          &lt;version&gt;2.1&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;jstl&lt;/artifactId&gt;
          &lt;version&gt;1.2&lt;/version&gt;
      &lt;/dependency&gt;
  &lt;/dependencies&gt;
  &lt;build&gt;
      &lt;plugins&gt;
        &lt;plugin&gt;
          &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
          &lt;version&gt;3.8.0&lt;/version&gt;
          &lt;configuration&gt;
            &lt;source&gt;1.8&lt;/source&gt;
            &lt;target&gt;1.8&lt;/target&gt;
          &lt;/configuration&gt;
        &lt;/plugin&gt;
      &lt;plugin&gt;
      &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
      &lt;version&gt;3.2.1&lt;/version&gt;
      &lt;configuration&gt;
        &lt;warSourceDirectory&gt;WebContent&lt;/warSourceDirectory&gt;
      &lt;/configuration&gt;
    &lt;/plugin&gt;
  &lt;/plugins&gt;
  </code></pre>
  
  <p>
  </p>
  
  <p>HomeController.java</p>
  
  <pre><code>package com.spring.controller;
  
  import java.text.DateFormat;
  import java.util.Date;
  import java.util.Locale;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.validation.annotation.Validated;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import com.spring.model.User;
  
  
  @Controller
  
  public class HomeController {
  
  /**
   * Simply selects the home view to render by returning its name.
   */
  @RequestMapping(value = "/", method = RequestMethod.GET)
  public String home(Locale locale, Model model) {
      System.out.println("Home Page Requested, locale = " + locale);
      Date date = new Date();
      DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
  
      String formattedDate = dateFormat.format(date);
  
      model.addAttribute("serverTime", formattedDate);
  
      return "home";
  }
  
  @RequestMapping(value = "/user", method = RequestMethod.POST)
  public String user(@Validated User user, Model model) {
      System.out.println("User Page Requested");
      model.addAttribute("userName", user.getUserName());
      return "user";
  }
  </code></pre>
  
  <p>}</p>
  
  <p>home.jsp</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%&gt;
  &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%&gt;
  &lt;%@ page session="false"%&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;Home&lt;/title&gt;
   &lt;/head&gt;
    &lt;body&gt;
  &lt;h1&gt;Hello world!&lt;/h1&gt;
      &lt;P&gt;The time on the server is ${serverTime}.&lt;/p&gt;
       &lt;form action="user" method="post"&gt;
         &lt;input type="text" name="userName"&gt;&lt;br&gt; 
         &lt;input type="submit" value="Login"&gt;
   &lt;/form&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>user.jsp</p>
  
  <pre><code>%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%&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;User Home Page&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;h3&gt;Hi ${userName}&lt;/h3&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>