title: Sending an Ajax request from a jsp page to a spring Controller
body: <p>I am trying to make an ajax call from a jsp page using the spring MVC framework to fetch some data from the server but I am getting the following error. </p>
  
  <pre><code>10-Dec-2015 11:53:05.349 WARNING [http-nio-8084-exec-14] org.springframework.web.servlet.PageNotFound.noHandlerFound No mapping found for HTTP request with URI [/EIMEnterprise/[object%20Object]] in DispatcherServlet with name 'spring-dispatcher'
  </code></pre>
  
  <p>No matter what I have as my URL parameter for my $.get call, it seems to attach an [object%20Object]] value at the end. Here is my Ajax Controller Class</p>
  
  <pre><code>@Controller
  public class AjaxController {
  
  @RequestMapping(value="/viewhiers.html", method=RequestMethod.GET)
  public @ResponseBody ArrayList&lt;HierarchyBean&gt; getHiersViaAjax(@RequestParam("versionID") int versionID) {
      //return an arraylist of HierarchyBean
  
  }
  
  }
  </code></pre>
  
  <p>Below is my web.xml file</p>
  
  
  
  <pre><code>&lt;web-app 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"
   version="3.1"&gt;
  
  &lt;display-name&gt;EIMEnterprise&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;
  </code></pre>
  
  <p></p>
  
  <p>And below is my jsp page with the following code</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          $(document).ready(function() {
              $('#versiontab tr td').click(function() {
                  //alert("Hello");
                  //highlight the current row and disable highlight on the other rows
                  $(this).closest("tr").addClass('highlightblue').siblings().removeClass('highlightblue');
  
                  //make an ajax call to populate the hierarchies
                  $.get({
                      url: '/EIMEnterprise/viewhiers.html?versionID=1',
                      type: 'GET',
                      success: function(data) {
                          alert("success");
                          /*
                          $.each(data, function (index, value) {
                              alert(index + " " + value);
                          });*/
                      }
                  });
              });
  
          });
  
      &lt;/script&gt;
  </code></pre>
  
  <p>And here is my spring-dispatcher-servlet.xml file</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
     xmlns:context="http://www.springframework.org/schema/context"
     xmlns:mvc="http://www.springframework.org/schema/mvc"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.springframework.org/schema/beans
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
     http://www.springframework.org/schema/context
     http://www.springframework.org/schema/context/spring-context-3.0.xsd
     http://www.springframework.org/schema/mvc
     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"&gt;
  
  &lt;!--Scan this package for any controller annotations--&gt;
  &lt;context:component-scan base-package="com.eimenterprise.controllers" /&gt;
  
  &lt;!--Used for using pathvariable with map--&gt;
  
  
  &lt;mvc:annotation-driven /&gt;
  &lt;mvc:resources location="/resources/" mapping="/resources/**" /&gt;
  
  &lt;bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="prefix"&gt;
          &lt;value&gt;/WEB-INF/&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name="suffix"&gt;
          &lt;value&gt;.jsp&lt;/value&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p></p>
  
  <p>Please let me know what I am doing wrong as it seems to append an object value at the end of the urL instead of sending it to the correct controller and thus cannot find the mapping. </p>