码迷,mamicode.com
首页 > 编程语言 > 详细

SpringMVC @RequestBody接收JSON报HTTP 415问题的解决方法

时间:2015-10-09 14:00:39      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:

现在做的一个项目是做app服务端的,需要从app接收json的请求数据,服务端框架用的是SpringMVC,所以自然而然的想到直接用@RequestBody来接收json数据,

格式如下:

public ResponseProtocolMap login(@RequestBody JSONObject requestJson,HttpServletRequest request) {
	ResponseProtocolMap responseProtocolMap = null;
	
	//中间内容省略。。。

	return responseProtocolMap;
}

刚开始导入的是org.json.jar的org.json.JSONObject的包,请求的时候,出现了415错误:

HTTP Status 415 -
type Status report
message
description The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.
Apache Tomcat/7.0.64

在这个问题上找了很久解决方法,都没有找到,本来还以为SpringMVC不支持直接接收json呢,后来将json包换成了net.sf.json-lib.jar的net.sf.json.JSONObject就解决问题了

注:测试了用ajax直接传json数据还是会出现415错误,如果直接用http请求post提交json的数据流,测试是正常的,不懂如果是用ajax请求要怎么接收,知道的朋友麻烦帮忙说下,谢谢。

SpringMVC @RequestBody接收JSON报HTTP 415问题的解决方法

标签:

原文地址:http://my.oschina.net/zchuanzhao/blog/514731

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!