I am working on a Ajax, JSON with Spring program and we are trying to see why the JSP page is not getting data back from Spring controller. I feel that it is and the ajax is not working right but the ajax programmer is telling me that nothing is coming back from Springs…
Can someone show me some example code that I can put into any JSP to display the json coming back from the following Spring controller.. also does anyone see anything up with this controller
@RequestMapping(value = "/getcerts", method = RequestMethod.GET)
public @ResponseBody JsonResponse getCertificates(@ModelAttribute(value="certificateData") CertificateData certificateData, BindingResult result ) {
log.debug("inside CertificateWebAjaxControllor");
JsonResponse res = new JsonResponse();
certificateData.setFirstName("Kurt");
certificateData.setLastName("Kostenbader");
certList.add(certificateData);
res.setStatus("SUCCESS");
res.setResult(certList);
return res;
}
You don’t have any JSP here; you’re using the
@ResponseBodyannotation to deliver the returned object (aJsonResponse) as the body of the HTTP response. To verify that the method works, you can:print the
resobject to your log with e.g.and then actually test that the method returns what it should by using something like Poster to send a properly-formatted request to your controller.