tuangtuangta 2015-06-14 06:16 采纳率: 0%
浏览 2103

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 2015-06-14 09:10
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog