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以上的包,真是(~哔!~)!

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向