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

背景

使用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”则该错误消除。

posted @ 2016-08-18 20:14  hongweigg  阅读(18)  评论(0)    收藏  举报