has been working on the interaction of Spring 3.1.1 MVC + dojo1.8 to map the page's JSON data directly to Java objects through spring MVC. It's consistent with the following anomaly.
Java.io.EOFException:No content to map to Object due to end of input at Org.codehaus.jackson.map.objectmapper._initforre
Ading (objectmapper.java:2775) at Org.codehaus.jackson.map.objectmapper._readmapandclose (ObjectMapper.java:2718) At Org.codehaus.jackson.map.ObjectMapper.readValue (objectmapper.java:1923) 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.readWithMessageConve Rters (abstractmessageconvertermethodargumentresolver.java:120) at Org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConve Rters (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) at Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod ( requestmappinghandleradapter.java:617) at Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal ( requestmappinghandleradapter.java:578) at Org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle (AbstracthandleRMETHODADAPTER.JAVA:80) at Org.springframework.web.servlet.DispatcherServlet.doDispatch (Dispatcherservlet.java : 923) at Org.springframework.web.servlet.DispatcherServlet.doService (dispatcherservlet.java:852) at Org.springframework.web.servlet.FrameworkServlet.processRequest (frameworkservlet.java:882) at Org.springframework.web.servlet.FrameworkServlet.doGet (frameworkservlet.java:779) at Javax.servlet.http.HttpServlet.service (httpservlet.java:621) at Javax.servlet.http.HttpServlet.service ( httpservlet.java:723)
After multiple tracking and debugging, this exception was found because dojo passed the JSON data to spring MVC as NULL, so it was not able to turn.
After careful examination of the code, it is discovered that the AJAX request sent with Get is the following code:
XHR ("/springmvcrestful/login", {
data:JSON.stringify (userInfo),
//query:json.stringify (UserInfo),// Add this to the URL display parameter
sync:true,
handleas: "JSON",
timeout:2000,
headers: {
' content-type ': ' Application/json;charset=utf-8 '
}
}). Then (function (response) {
Need to modify to send POST request:
Xhr.post ("/springmvcrestful/login", {
data:JSON.stringify (userInfo),
//query:json.stringify (UserInfo), Add this to the URL display parameter
sync:true,
handleas: "JSON",
timeout:2000,
headers: {
' content-type ': ' Application/json;charset=utf-8 '
}
}). Then (function (response) {
At the same time, spring's controller is also post:
@RequestMapping (value = "/login", method = requestmethod.post) public
@ResponseBody Jsonresult Login (@RequestBody User user,
httpservletrequest request, httpservletresponse response) {
log.info (user.tostring ());
Request.getsession (). setattribute (Constants.user, USER);
return new Jsonresult (true, ' return OK ');
}
Finally done.