not acceptable according to the request "accept" headers 问题解决

来源:互联网 发布:淘宝中学科学实验室 编辑:程序博客网 时间:2024/05/18 15:04

背景

使用swfupload 上传文件,后台用spring controller进行处理,报not acceptable according to the request "accept" headers错误。

原因

swfupload上传的HTTP头中,发送的指令Accept:text/*,而Spring Controller中返回的为application/json:

    @RequestMapping(value = "/upload", method = RequestMethod.POST, produces = "application/json")
    public @ResponseBody String login(
            @RequestParam MultipartFile[] myfiles,        
            HttpServletRequest request,
            HttpServletResponse response) {
            //...

  }

返回类型使用produces参数指定,返回的数据内容类型与请求的不一致,故报错。

解决

将produces参数值修改为“text/json”则该错误消除。

0 0
原创粉丝点击