spring mvc 文件上传 ajax 异步上传

异常代码:

1.the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is true
2.The current request is not a multipart request

 先看 spring mvc 配置上传文件处理器解析

没感觉有什么问题。 

跟源码:

这里有一个双重判断

必须 请求方式是POST 加 request 的contentType 必须是 multipart/开头。如果不符合就会返回一个false 

 dispatcherServlet:

后台代码:

前台:JSP

js代码:

 

总结:

不管是同步提交还是异常提交要满足两个条件。

一个是POST,一个contentType: 要以multipart/开头。

 表单默认属性值:

原文地址:https://www.cnblogs.com/1-Admin/p/9238753.html