0

I am trying to get JSON response from spring controller by AJAX call in jsp. Below is code.

Spring MVC Controller:

 @RequestMapping(value = "/data.htm", method = RequestMethod.GET, headers="Accept=*/*",consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public TestVO testMe(){
    TestVO testVO = manageService.getData(2);
    return testVO ; //I am getting testVo but after returning from here I am getting 406 Not Acceptable issue
}

Ajax call in JSP:

   $.ajax({
                 url: url2,
                 type: "GET",
                 beforeSend: function(xhr) {
                     xhr.setRequestHeader("Accept", "application/json");
                     xhr.setRequestHeader("Content-Type", "application/json");
                },
                success: function(smartphone) {alert("hi");
                }
   });

Please suggest for solution.

Regards

S Singh
  • 1,403
  • 9
  • 31
  • 47
  • without knowing more details i would inspect two things, if the TestVO class has properly named getter/setter methods, and second, if the dependencies for json converter match the spring version, check more http://stackoverflow.com/questions/26825276/spring-4-restcontroller-json-characteristics-not-acceptable-according-to-the-re/26826136#26826136 – Master Slave Feb 24 '15 at 12:45
  • you don't have to set the request headers specifically, Jquery provides elegant way of doing this using dataType and content-type. can you also set the charset while sending the request and give it a try? – minion Feb 24 '15 at 13:36
  • seems you are missing jackson library,check your pom.xml. – dReAmEr Feb 24 '15 at 17:24
  • @Tyrion Lannister I am using jackson-mapper-asl-1.7.4, jackson-core-asl-1.7.4 and spring-4.0.5.RELEASE – S Singh Feb 25 '15 at 06:47

0 Answers0