title: Getting HTTP 404 Error while using @PathVariable annotation in Spring MVC
body: <p>I am a beginner in Spring MVC and trying to execute a demo spring program given in tutorial </p>
  
  <p><a href="https://www.youtube.com/watch?v=dDWNTR0-rns&amp;list=PLBgMUB7xGcO31B2gBmy1igpZn6LK78-CJ&amp;index=9" rel="nofollow noreferrer">https://www.youtube.com/watch?v=dDWNTR0-rns&amp;list=PLBgMUB7xGcO31B2gBmy1igpZn6LK78-CJ&amp;index=9</a></p>
  
  <p>While running the program i am getting HTTP 404 error and description is "The origin server did not find a current representation for the target resource or is not willing to disclose that one exists". Can someone please help me to resolve this issue.</p>
  
  <p><strong>web.xml</strong></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://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"&gt;
    &lt;display-name&gt;FirstSpringMVCAnnotations&lt;/display-name&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;spring-dispatcher&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;spring-dispatcher&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;  
  
  &lt;/web-app&gt; 
  </code></pre>
  
  <p><strong>spring-dispatcher-servlet.xml</strong></p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      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.xsd
      http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context.xsd
      http://www.springframework.org/schema/mvc
      http://www.springframework.org/schema/mvc/spring-mvc.xsd"&gt;
  
      &lt;context:component-scan base-package = "com.demo.controller"/&gt; 
  
      &lt;mvc:annotation-driven/&gt;
  
      &lt;bean id = "viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;  
          &lt;property name="prefix" value="/WEB-INF/" /&gt;  
          &lt;property name="suffix" value=".jsp"/&gt;  
      &lt;/bean&gt;  
  &lt;/beans&gt; 
  </code></pre>
  
  <p><strong>PathVariableDemoController</strong> </p>
  
  <pre><code>package com.demo.controller;
  
  import java.util.Map;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.portlet.ModelAndView;
  
  @Controller
  @RequestMapping("/greeting")
  public class PathVariableDemoController {
  
      @RequestMapping("/hello/{username}/{countryname}")
      public ModelAndView helloWorld(@PathVariable("username") String username, @PathVariable("countryname") String countryname) {
          System.out.println("Inside PathVariableDemoController...");
          ModelAndView modelView = new ModelAndView("Greetings");
          String msg = "Hello " + username + " You are from " + countryname;
          modelView.addObject("greetingsMessage", msg);
          System.out.println("End PathVariableDemoController helloWorld()...");
          return modelView;
      }
  } 
  </code></pre>
  
  <p><strong>Greetings.jsp</strong></p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;h1&gt;Message is: ${greetingsMessage}&lt;/h1&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Project Structure:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/VG1Ui.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VG1Ui.jpg" alt="enter image description here"></a></p>
  
  <p><strong>Error Screenshot:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/G9V7U.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/G9V7U.jpg" alt="enter image description here"></a></p>