title: Request parameter not received in spring mvc using Ajax
body: <p>I'm not able to send a parameter using Ajax jquery to my spring class. Here is the code . </p>
  
  <pre><code>package com.controller;
  
  
  
  
  @Controller  
  public class HelloWorldController {
  
      private static final Logger logger = LoggerFactory.getLogger(HelloWorldController.class);
  
  /*@Autowired
  EmployeeImpl employee;*/
  
  @RequestMapping(value = "/hello", method =  {RequestMethod.POST,RequestMethod.GET}) 
  public @ResponseBody String ajaxJsonRequest(@RequestParam("firstname") String firstname) 
  {
  
      System.out.println("***** TEST METHOD *****");
      System.out.println(firstname);
      return "Hello "+firstname;
  }    
  }  
  </code></pre>
  
  <h2>My Ajax call</h2>
  
  <pre><code>$.ajax({
          type: "POST",
          contentType: "application/json",
          url: "/SpringProject/hello",
          data: JSON.stringify(data),
          dataType: 'json',
          timeout: 600000,
          success: function (data) {
              alert("success");
          },
          error: function (e) {
              alert("fail");
          }
  });
  </code></pre>
  
  <h2>Web.xml</h2>
  
  <pre><code>&lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns="http://java.sun.com/xml/ns/javaee"  xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&gt;
  &lt;display-name&gt;SpringProject&lt;/display-name&gt;
  &lt;welcome-file-list&gt;   
    &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
  &lt;/welcome-file-list&gt;
  
  &lt;!-- &lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;/WEB-INF/lib/soapservice-servlet.xml&lt;/param-value&gt;
   &lt;/context-param&gt; --&gt;
  
  &lt;!--    &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
    &lt;/listener&gt;
   --&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;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;*.html&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  </code></pre>
  
  <p>Error which I'm getting is </p>
  
  <pre><code>http://localhost:8080/SpringProject/hello Failed to load resource: the server responded with a status of 404 (Not Found)
  </code></pre>
  
  <p>I suppose that there should be problem in the config part of putting the URl...</p>