The server refused this request because the request entity is in a format not supported by the requested resource for the requested method

1、Spring Mvc 配置

<?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/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-scan base-package="com.test.controller">
</context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value=""></property>
<property name="suffix" value=".jsp"></property>
</bean>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
<bean class="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>
<bean class="org.springframework.http.converter.ResourceHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter"/>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"></bean>
</list>
</property>
</bean>
<mvc:annotation-driven />
<mvc:default-servlet-handler />
</beans>

引用 jackson jar包:jackson-annotations-2.1.1.jar、jackson-core-2.1.1.jar、jackson-databind-2.1.1.jar。

2、Controller代码

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 class ReportTypeController extends BaseController { @RequestMapping("/set")
@ResponseBody
public String set(@RequestBody List<User> settingBeans,HttpServletRequest request){return "";
}
}

3、ajax请求:

       var userList= new Array();
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){
}
});

如果实体中某个boolean属性定义为isFirst,js中为此属性传值的时候应为:{first:true}之类

spring mvc ajax 提交复杂数组类型的更多相关文章

  1. Spring MVC ajax提交方式

    使用jquery的ajax的方式来提交 第一种,以json对象的形式提交 var jsonData = { "name" : "zhangsan", " ...

  2. Spring MVC url提交参数和获取参数

    [转载:http://blog.csdn.net/mahoking] 普通URL提交参数         该格式url为:url.do?param1=mahc&param2=8888.00 需 ...

  3. mvc ajax提交数组参数(转)

    http://blog.csdn.net/lonestar555/article/details/10192595/ 在action中的参数以数组方式接收数据 一.表单方式 1.提交Form < ...

  4. Spring MVC Ajax 嵌套表单数据的提交

    概述 在一些场景里,某个大表单里常常嵌套着一个或若干个小逻辑块,比如以下表单里"设计预审"中包括了一个子模块表单"拟定款项". 在这种情况下该怎么去设计实体类以 ...

  5. Spring MVC+ajax进行信息验证

    本文是一个ajax结合Spring MVC使用的入门,首先我们来了解一下什么是Ajax AJAX 不是新的编程语言,而是一种使用现有标准的新方法.AJAX 最大的优点是在不重新加载整个页面的情况下,可 ...

  6. spring mvc ajax异步文件的上传和普通文件上传

    表单提交方式文件上传和ajax异步文件上传 一:首先是我在spring mvc下的表单提交方式上传 ssm的包配置我就不一一详细列出来了,但是上传的包我还是列出来 这一段我也不知道怎么给大家讲解就是直 ...

  7. Spring MVC请求参数绑定 自定义类型转化 和获取原声带额servlet request response信息

    首先还在我们的框架的基础上建立文件 在domian下建立Account实体类 import org.springframework.stereotype.Controller; import org. ...

  8. Spring MVC 处理列表和数组数据

    SpringMVC处理列表和数组类型: 当form提交多个参数时,可以使用@RequestParam(value="")注解将其注入到列表或数组中,否则参数无法传值 1 contr ...

  9. 在Spring MVC 中配置自定义的类型转换器

    方法一: 实现spring mvc 自带的 Formatter 接口 1.创建一个类来实现Formatter接口 import org.springframework.format.Formatter ...

随机推荐

  1. 循序渐进Python3(三) -- 2 -- 内置函数

    上一篇我们介绍了21个最常用到的函数,简单列一下,帮助回忆巩固: 1.abs 2.dict 3.float 4.help 5.input 6.int 7.len 8.list 9.max 10.min ...

  2. Ruby-打包程序

    1.下载 ocra-1.3.1.gem 文件 2.打开“start Command prompt with ruby”  命令窗口 3.输入 “gem install e:\ocra-1.3.1.ge ...

  3. Spring----->projects----->Spring Security

    1.Spring Security概述 Spring Security是spring社区若干projects中的一个 Spring Security用于为基于spring开发的application提 ...

  4. @Configuration 和 @Bean

    1. @Bean: 1.1 定义 从定义可以看出,@Bean只能用于注解方法和注解的定义. @Target({ElementType.METHOD, ElementType.ANNOTATION_TY ...

  5. Cadence16.6安装破解

    1.软件安装 1.运行stepup.exe.出现下面界面后开始安装License manager和project installation. 注意:只安装第一项License manager和第二项p ...

  6. Selenium2+python自动化2-pip降级selenium3.0

    selenium版本安装后启动Firefox出现异常:'geckodriver' executable needs to be in PATH selenium默默的升级到了3.0,然而网上的教程都是 ...

  7. Python全栈之路-----基础篇

    Python诞生 Python是著名的”龟叔“Guido van Rossum(吉多·范罗苏姆)在1989年圣诞节期间,为了打发无聊的圣诞节而编写的一个编程语言. Python语法很多来自C,但又受到 ...

  8. Deep Learning(1)-Introduction学习总结

    学习DL搁置很久了,终于下定决心开始咯~~ Deep Learning(Ian Goodfellow&&Yoshua Bengio&&Aaron Courville)- ...

  9. 2016---ios面试题

    1.对数组中的元素去重复 例如:   1 2 3   NSArray *array = @[@"12-11", @"12-11", @"12-11&q ...

  10. 小甲鱼python视频弟十一讲(课后习题)

    1.修改列表里的值 list1 = [,,[,,,[,,,,] list1[] = print(list1) list1[][][] = '?' print(list1) 2.列表的排序(sort) ...