struts2和springmvc混合项目,上传文件报错

12 阅读1分钟

问题

控制器的方法代码

@PostMapping("/uploadExcel2")
public String uploadExcel2(@RequestParam("file") MultipartFile file) {

报错

HTTP状态 400 - 错误的请求


类型 状态报告

消息 Required request part 'file' is not present

描述 由于被认为是客户端对错误(例如:畸形的请求语法、无效的请求信息帧或者虚拟的请求路由),服务器无法或不会处理当前请求。


Apache Tomcat/8.5.99

原因

因为struts2先拦截了,先读了文件流

导致spring读不到文件流

解决方法

struts2排除掉springmvc请求地址


配置文件

struts.properties

struts.action.excludePattern = /rest/xxx