i new spring
. previous search in google says can send json
data spring controller
using @requestbody , can data in controller.
but when used @requestbody
, doesn't allow request controller .
function sendjson(){ var jsondata = {"name":"xxx","age":"20","hobby":"tv"}; /alert("json data : \n\n\n"+jsondata); $.ajax({ type: 'post', datatype: 'json', url: contexpath + "/sender.html", //datatype: "html", //contenttype: "application/x-www-form-urlencoded; charset=utf-8", contenttype: "application/json" data : json.stringify(jsondata), success: function(data, textstatus ){ alert("success"); $("#result").html(data.name+"data.age+" "+data.hobby); }, error: function(xhr, textstatus, errorthrown){ //alert('request failed'+errorthrown); } }); }
my controller
,
@requestmapping(value = "sender.html", method=requestmethod.post) public @responsebody person sendmessage(@requestbody persons person){ system.out.println("test.........."); system.out.println(person.getname()+ " "+person.getage()+" "+person.gethobby()+"\n"); return persons; }
but request blocks.
am sending correct json data
controller
matches java bean
?
hope our stack users me.
please check java bean class name matches json data.
Comments
Post a Comment