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 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺