Error to Pass JSON data from JSP to controller in ResponseBody.
07:13:53.919 DEBUG o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - Resolving exception from
I made some minor modification to you code and tested it with a spring project that I have and it works, The logic will only work with POST if I use GET it throws an error with invalid request. Also in your ajax call I commented out commit(true), the browser debugger flagged and error that it is not defined. Just modify the url to fit your Spring project architecture.
$.ajax({
url: "/addDepartment",
method: 'POST',
dataType: 'json',
data: "{\"message\":\"abc\",\"success\":true}",
contentType: 'application/json',
mimeType: 'application/json',
success: function(data) {
alert(data.success + " " + data.message);
//commit(true);
},
error:function(data,status,er) {
alert("error: "+data+" status: "+status+" er:"+er);
}
});
@RequestMapping(value="/addDepartment", method=RequestMethod.POST)
public AjaxResponse addDepartment(@RequestBody final AjaxResponse departmentDTO)
{
System.out.println("addDepartment: >>>>>>> "+departmentDTO);
AjaxResponse response=new AjaxResponse();
response.setSuccess(departmentDTO.isSuccess());
response.setMessage(departmentDTO.getMessage());
return response;
}