【发布时间】:2015-09-19 02:12:15
【问题描述】:
我对 spring 还很陌生,想要以正确的方式发出帖子请求。我有一个要发布到服务器的 json 对象列表 例如
var list = [{name:"abc",age:23},{name:"xyz",age:22},{name:"xcx",age:33}]
我正在以这种方式使用 xhr 在 google 关闭中向我的服务器发出发布请求
model.xhrPost(id,url,"list="+JSON.stringify(this.list),callback);
这就是我的控制器的样子
@RequestMapping(value={"/getInput"}, method = RequestMethod.POST)
@ResponseBody
public String logClientError(ModelMap model, HttpServletRequest request, HttpServletResponse response) throws Exception{
JSONObject result = new JSONObject();
try{
String errorObj = request.getParameter("list");
JSONArray errors = new JSONArray(errorObj);
some more code here which loops through the list...
result.put("isSuccess", true);
return result.toString();
}catch(JSONException e){
result.put("isSuccess", false);
return result.toString();
}
}
简而言之,我通过传递查询字符串参数来发出发布请求。这是正确的方式还是应该将内容发布在正文中?如果我在正文中发布,我必须进行哪些更改?
【问题讨论】:
-
是的,谢谢。它确实给了我一个想法
标签: javascript java json spring rest