The server refused this request because the request entity was in a format does supported by the requested resource for the Requested method
1. Spring MVC Configuration
<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:tx= "Http://www.springframework.org/schema/tx"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:mvc= "Http://www.springframework.org/schema/mvc"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-3.0.xsd Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/ Spring-tx-3.0.xsd Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/ Spring-context-3.0.xsd Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/ Spring-mvc-3.0.xsd "> <Context:component-scanBase-package= "Com.test.controller"> </Context:component-scan> <Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver"> < Propertyname= "prefix"value=""></ Property> < Propertyname= "suffix"value= ". jsp"></ Property> </Bean> <Beanclass= "Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> < Propertyname= "Messageconverters"> <List> <Beanclass= "Org.springframework.http.converter.ByteArrayHttpMessageConverter"/> <Beanclass= "Org.springframework.http.converter.StringHttpMessageConverter"> < Propertyname= "Supportedmediatypes"> <List> <value>text/html; Charset=utf-8</value> <value>Application/json; Charset=utf-8</value> </List> </ Property> </Bean> <Beanclass= "Org.springframework.http.converter.ResourceHttpMessageConverter"/> <Beanclass= "Org.springframework.http.converter.xml.SourceHttpMessageConverter"/> <Beanclass= "Org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter"/> <Beanclass= "Org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"/> <Beanclass= "Org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"></Bean> </List> </ Property> </Bean> <Mvc:annotation-driven/> <Mvc:default-servlet-handler/></Beans>
Refer to the Jackson Jar package: Jackson-annotations-2.1.1.jar, Jackson-core-2.1.1.jar, Jackson-databind-2.1.1.jar.
2. Controller code
PackageCom.test.controller;ImportOrg.springframework.stereotype.Controller;Importorg.springframework.stereotype.Repository;ImportOrg.springframework.web.bind.annotation.RequestBody;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.bind.annotation.RequestParam;ImportOrg.springframework.web.bind.annotation.ResponseBody;Importjavax.servlet.http.HttpServletRequest;Importjava.util.ArrayList;Importjava.util.List;/*** Created by Administrator on 2015/2/28.*/@Controller @requestmapping ("/report") Public classReporttypecontrollerextendsBasecontroller {@RequestMapping ("/set") @ResponseBody PublicString Set (@RequestBody list<user>settingbeans,httpservletrequest request) {return""; }}
3. Ajax requests:
var New Array (); Userlist.push ({ID:1,name: "Zhangsan"}); Userlist.push ({ID:2,name: "Lisi"}); $.ajax ({ "/report/set", Type:"POST", data:JSON.stringify (userlist), DataType:"JSON", contentType:"Application/json", success:function (data) { },error:function(data) { } });
Spring MVC Ajax commits complex array types