背景
使用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”则该错误消除。
本文介绍了一个关于使用SWFUpload上传文件时遇到的问题,即后台使用Spring Controller处理时出现的“not acceptable according to the request 'accept' headers”错误。问题在于请求接受的内容类型与控制器返回的内容类型不符。文章提供了具体的解决方案。
784

被折叠的 条评论
为什么被折叠?



