I am making an ajax call from javascript to my controller and returning an Object.
I am sending Json
from ajax and retrieving in controller by @RequestBody
and sending Json
back from controller using @ResponseBody
.
My functionality is perfectly working until i had to add .htm in Request mapping.
Now it is throwing HttpMediaTypeNotAcceptableException
when i am returning same Object(returning just String is working even with .htm).
this is my ajax call from js:
var user = new Object();
user.id = 1;
user.name = "Noor";
$.ajax(contextPath + "/createUser.htm", {
type: 'POST',
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify(user),
success: function(result) {
alert("Success");
},
error: function(jqXHR, textStatus, errorThrown) {
alert("Fail");
}
});
This is my controller:
@RequestMapping(value = "/createUser.htm", method = RequestMethod.POST)
@ResponseBody
public ResultDTO createUser(@Valid @RequestBody CitizenUser user){
log.info("Enter Controller");
..
..
..
log.infor("Exit");
return new User(100,"DADA");
}
This is perfectly working fine without .htm in mapping.
But my project requires .htm in mapping, so i just cannot remive it.
Can any one help me to fix this issue??