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"? ><beans xmlns="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/beanshttp//www.springframework.org/schema/beans/spring-beans-3.0.xsdhttp//Www.springframework.org/schema/txhttp//www.springframework.org/schema/tx/spring-tx-3.0.xsdhttp//Www.springframework.org/schema/contexthttp//www.springframework.org/schema/context/spring-context-3.0.xsdhttp//Www.springframework.org/schema/mvchttp//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"> <property name="prefix"Value=""></property> <property name="suffix"Value=". JSP"></property> </bean> <beanclass="Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> <property name="messageconverters"> <list> <beanclass="Org.springframework.http.converter.ByteArrayHttpMessageConverter"/> <beanclass="Org.springframework.http.converter.StringHttpMessageConverter"> <property name="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
Package Com.test.controller;import Org.springframework.stereotype.controller;import Org.springframework.stereotype.repository;import Org.springframework.web.bind.annotation.requestbody;import Org.springframework.web.bind.annotation.requestmapping;import Org.springframework.web.bind.annotation.requestparam;import Org.springframework.web.bind.annotation.responsebody;import Javax.servlet.http.httpservletrequest;import Java.util.arraylist;import java.util.List;/** * Created by Administrator on 2015/2/28.*/@Controller @requestmapping ("/report") Public classReporttypecontroller extends Basecontroller {@RequestMapping ("/set") @ResponseBody PublicStringSet(@RequestBody list<user> settingbeans,httpservletrequest request) {return ""; }}
3. Ajax requests:
varuserlist=NewArray (); Userlist.push ({ID:1, Name:"Zhangsan"}); Userlist.push ({ID:2, Name:"Lisi"}); $.ajax ({URL:"/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