Spring MVC Ajax commits complex array types

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.