org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Current request is not a multipart request


在springMVC中写文件上传的时候,前端页面是jsp,具体代码是

<form action="/user/up/file" method="post">
<input type="file" name="upfile" >
<button>提交</button>
</form>


在controller文件中的代码如下
@PostMapping("/up/file")
@ResponseBody
public String fileup(@RequestParam("upfile")MultipartFile mf){
logger.info("name:"+mf.getName());
logger.info("size:"+mf.getSize());
Path path=Path.of("D://kfm"+mf.getOriginalFilename());
try {
mf.transferTo(file);
InputStream in= mf.getInputStream();
Files.copy(in,path,StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
System.out.println("上传文件错误");
e.printStackTrace();
}
return "success";
}
会出现如标题的错误,原因是:在前端传参数时,只传入文件名,没有上传文件,因此,controller中接收时会出现传入参数错误。

解决方法:
<form action="/user/up/file" method="post" enctype="multipart/form-data">
<input type="file" name="upfile" >
<button>提交</button>
</form>

multipart/form-data是将文件以二进制的形式上传,这样可以实现多种类型的文件上传。



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



猜您在找 org.springframework.web.multipart.MultipartException: The current request is not a multipart request 上传文件Request processing failed;nested exception is org.springframework.web.multipart.MultipartException:Failed to parse multipart servlet request;multipart/form-data request failed.(**没有权限**) error:org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException 成功解决 org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalStateException:报错 org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.jboss.resteasy.plug org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [/tmp/tomcat.1428942566812653608 org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: 临时上传路径[D:\tomcat\work\Catalina\localhost\ROOT]无效 org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: Unable to process parts as no multi-part configura Spring MVC报异常:org.springframework.web.util.NestedServletException: Request processing failed
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM