2 tuangtuangta tuangtuangta 于 2015.06.14 14:16 提问

spring4mvc-ajax-requestbody解析不了arraylist报415错误

直接上代码
script代码:

 function sendMsg3(){
            var test=new Array();
            test[0]="呵呵1";
            test[1]="呵呵2";
            test[2]="呵呵3";
            test[3]="呵呵4";
            test[4]="呵呵5";
            var userJsonStr=JSON.stringify(test);
            $.ajax({
                type:"POST",
                data:userJsonStr,
                url:"getJson3.spring?t="+new Date().getTime(),
                dataType:"json",
                contentType:"application/json"
            });
            alert(userJsonStr);         
        }

java里的代码:

 @RequestMapping("/getJson3")
    public String getJson3(@RequestBody ArrayList<String> list) {
        for (String str : list) {
            System.out.println(str);
        }
        System.out.println("呵呵come here");
        return "index.jsp";
    }

spring-mvc配置:

 <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-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.1.xsd">
    <context:component-scan base-package="controller"/>
    <mvc:annotation-driven />
</beans>

lib包里有jack-all的包如图:
图片说明

触发ajax方法后,控制台 那边愣是没啥反应,客户端这边报415的错误unsupported media type,求各路大神支援

1个回答

tuangtuangta
tuangtuangta   2015.06.14 17:10

原来要加jackson2以上的包,真是(~哔!~)!

Csdn user default icon
上传中...
上传图片
插入图片