我工作的一个应用程序用SpringMVC我要求使用Ajax调用的数据回来的JSON对象从数据库中的一些数据。 我现在有这个数据发送回服务器进行一些处理,并返回到窗体。
但是我在浏览器中得到一个错误服务器遇到阻止它完成此请求内部错误。 在调查我看到这个错误日志:
错误日志
Controller [com.crimetrack.web.MapController]
Method [public com.crimetrack.business.Marker com.crimetrack.web.MapController.getNewCoordinates(com.crimetrack.business.Marker) throws java.lang.Exception]
java.io.EOFException: No content to map to Object due to end of input
at org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:1324)
at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:1275)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:941)
at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.readInternal(MappingJacksonHttpMessageConverter.java:124)
at org.springframework.http.converter.AbstractHttpMessageConverter.read(AbstractHttpMessageConverter.java:153)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:120)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:91)
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:71)
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:75)
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:156)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:117)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
AJAX调用
$('#getCoordinates').on('click',function(){
$.each(global_citizens, function(i, gc){
$.ajax({
type:'GET',
url:'getNewCoordinatesForMarkers.htm',
contentType: 'application/json',
data:{citizens:JSON.stringify(global_citizens[i])},
dataType: 'json',
success:function(new_citizens){
$.each(new_citizens, function(i, c) {
console.log(c.name + ' | ' + c.socialSecurityNumber + ' | ' + c.lat+ ' | ' +c.lng);
});
}
});
});
});
调节器
@RequestMapping(value = "getNewCoordinatesForMarkers.htm", method = {RequestMethod.GET}, headers = {"content-type=application/json"})
public @ResponseBody Marker getNewCoordinates(@RequestBody Marker citizens)throws Exception{
logger.info("Getting Markers");
Marker citizenMarker = this.markerManager.getNextLocation(citizens);
return citizenMarker;
}
Marker.java
public class Marker implements Serializable{
private int socialSecurityNumber;
private String name;
private int citizenType;
private double lat;
private double lng;
//getters and setters
JSON数据 -taken从萤火控制台
citizens{"name":"Jessie Small","lat":10.670044,"lng":-61.515305,"socialSecurityNumber":1999020214,"citizenType":3}
萤火 -内容被传递
Connection close
Content-Length 3696
Content-Type text/html;charset=utf-8
Date Tue, 07 May 2013 05:52:09 GMT
Server Apache-Coyote/1.1
Request Headers
Accept application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Content-Type application/json
Cookie tinymcePasteText=1; JSESSIONID=CC4F12D00C836FE0DB86D2493556275C
Host localhost:8084
Referer http://localhost:8084/crimeTrack/crimeTrackMap.htm
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0
X-Requested-With XMLHttpRequest