java - Spring MVC POST method -
here controller class snippet
@requestmapping(value = "/createagent", method = requestmethod.post) @responsebody public string createagent(@requestbody string json) { system.out.println(json); }
how go passing json object method. can pass through url in way? if pass way(although seems wrong),
http://localhost:8080/surveyapp3/createagent/{"a_id": 8746574632, "pwd": "abcd", "pim_id": 3, "m_id":9738247882}
i error saying
warning: no mapping found http request uri [/surveyapp3/createagent/%7b%22a_id%22:%208746574632,%20%22pwd%22:%20%22abcd%22,%20%22pim_id%22:%203,%20%22m_id%22:9738247882%7d] in dispatcherservlet name 'spring'
i tried using ajax request welcome file index.jsp
<%@ page language="java" contenttype="text/html; charset=iso-8859-1" pageencoding="iso-8859-1"%> <!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <title>insert title here</title> </head> <body> <script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script type="text/javascript" > function sendajax() { $.ajax({ url: "/createagent", type: 'post', datatype: 'json', data: "{\"a_id\":7645534265,\"pwd\":\"abcd\", \"pim_id\":3, \"m_id\":9738247882}", contenttype: 'application/json', success: function(data) { alert(data.a_id + " " + data.pwd); }, error:function(data,status,er) { alert("error: "+data+" status: "+status+" er:"+er); } }); } </script> </body> </html>
when go url,
http://localhost:8080/surveyapp3/createagent
i error saying method not supported. still new topic , not able figure out how send json object parameter post method. going wrong?
thanks!
in spring controller every method must return view name. in code missing that's why getting warning: no mapping found http request uri error, add
return "viewname" code.
also, use @modelattribute --- objects
@pathvariable --- strings
@requestparam --- string arrays.
hope work...
Comments
Post a Comment