/*ajax request to servlet to perform update operation*/
var savedata={
video_Title:videotitle,
video_duration:videoduration,
video_Url:videourl,
video_Description:videodescription
};
$.ajax({
url:'videoUpdate',
type:'POST',
cache:false,
data: savedata,
contentType: "application/json; charset=utf-8",
success: function(response) {
alert("Updated Successfully");
},
error:function()
{
alert("oops sorry something went wrong. we apologize for the inconvenience");
}
});
/*Controller Class*/
@RequestMapping(value ="videoUpdate",method = RequestMethod.POST,consumes=MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody Status updateVideo(@RequestBody Video video) {
try {
System.out.println("update servlet");
dataServices.updateVideo(video);
return new Status(1,"video updated Successfully");
}
catch (Exception e) {
return new Status(0,e.getMessage().toString());
}
}
我的问题是如何收到我的servlet class.Is Ajax的JSON请求的数据,这是赶上了一组数据从阿贾克斯Spring MVC中的正确方法或者需要其他注释以避免400错误!?400坏请求!当我尝试发送Ajax请求在Spring MVC中,以Servlet的
登录你的错误的JSON精确匹配,你会得到什么错误实际信息。 – Kayaman
@codeseeker当您使用'@RequestBody Video video'时,您发送的数据是否与模型类绑定?似乎更多的请求数据不匹配? –