转载自: http://www.cnblogs.com/ysdxz207/p/3652792.html


在Spring mvc 文件上传中抛出异常

2014-4-8 20:11:49 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet springMvc threw exception
java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
at com.sakura.controller.juan.JuanAlbumController.add(JuanAlbumController.java:87)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:440)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:428)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)

错误行为:

MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;

而在 Spring 配置中也已有

<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <!-- set the max upload size100MB -->
    <property name="maxUploadSize">
              <value>104857600</value>
    </property>
    <property name="maxInMemorySize">
        <value>4096</value>
    </property>
</bean>

仍然报错

解决办法:

form 中加入 enctype ="multipart/form-data"

<form id="resourceAddForm" method="post" enctype ="multipart/form-data">
使用Spring中Service更新模块测试代码时出错org.springframework.jdbc.BadSqlGrammarException: ### Error updating data

使用Spring中Service更新模块测试代码时出错org.springframework.jdbc.BadSqlGrammarException: ### Error updating data

创建javaweb项目配置pom.xml文件导入子父级依赖时出现错误由于缓存问题引起的解决办法org.springframework.boot:spring-boot-starter-parent:p

创建javaweb项目配置pom.xml文件导入子父级依赖时出现错误由于缓存问题引起的解决办法org.springframework.boot:spring-boot-starter-parent:p

org.springframework.web.multipart.MultipartException: Current request is not a multipart request

org.springframework.web.multipart.MultipartException: Current request is not a multipart request

org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request

org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [C:\Users\admin\AppData\Local\Temp\tomcat.391789735741820346.8177\work\Tomcat\localhost\

【常见错误】org.springframework.web.multipart.MultipartException request is not a multipart request

检查请求类型和内容类型MultipartException 错误通常发生在请求类型不是 multipart/form-data 或者内容类型不是预期的类型时。因此,要解决这个错误,需要确保请求的类型和内容类型正确。以下是一些检查步骤:检查请求类型确保发送到服务器的请求的 HTTP 方法为 POST,并且 Content-Type 为 multipart/form-data。可以通过浏览器

【Java异常】org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet requ

本文目录一、背景描述二、异常分析三、解决方案3.1 方案一:重启本项目3.2 方案二:修改配置文件(application.properties或者.yml配置文件)3.3

spring cloud gateway 报错 cannot be cast to org.springframework.core.io.buffer.NettyDataBufferFactory

配置好项目后访问报错如下:java.lang.ClassCastException: org.springframework.core.io.buffer.DefaultDataBufferFactory cannot be cast to org.springframework.core.io.buffer.NettyDa...

Could not instantiate bean class [org.springframework.web.multipart.MultipartFile]: Specified class

如果在使用SpringMVC中使用文件上传的MultipartFile对象时,出现了以下的错误:Could not instantiate bean class [org.springframework.web.multipart.MultipartFile]: Specified class那么就在参数前加入: @RequestParam注解即可…原因就是传过来的参数名称...

spring boot 踩坑日记: Current request is not of type [org.springframework.web.multipart.MultipartHttpSer

错误信息:java.lang.IllegalStateException: Current request is not of type [org.springframework.web.multipart.MultipartHttpServstFacade@1fa4d44b错误位置:...

错误org.springframework.web.filter.CharacterEncodingFilter cannot be cast to jakarta.servlet.Filter

解决方法:替换tomcat版本,使用tomcat9 ...

org.apache.shiro.web.servlet.ShiroHttpServletRequest cannot be cast to org.springframwork.web.mult..

在用dwz框架+spring MVC时上传文件报的错 详细错误例如以下: 事实上就是一个类型转换错误,但却研究了好长时间,怎么都不知道哪里错了。由于前面卸过一个文件上传的和这个差点儿相同,那个就没有问题。 问题解决:事实上包这个错误有两个原因:一个是表单的属性,有文件上传是,表单的类型一定要是for

spring boot 上传文件出错:org.springframework.web.multipart.MultipartException: Could not parse multipart s

org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.io.IOException: The temporar

Java之——java.lang.NoSuchMethodException: [org.springframework.web.multipart.MultipartFile;.()

ava.lang.NoSuchMethodException: [org.springframework.web.multipart.MultipartFile;.<init>()at java.lang.Class.getConstructor0(Class.java:2721)at java.lang.Class.getDeclaredConstructor(Class.java:

org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'multipart/form-data;bounda

最近在做一个图片上传,遇到这了这种情况,在入参 body 中同时传入文件和其它参数信息结果出现如题异常。 特别在此记录解决办法,以供大家参考。 @PostMapping("/app")public ResponseEntity<Integer> createApplication(@RequestB ...

16-图片上传那些事 org.springframework.web.multipart.MultipartException: The current request is not a multipart request

我曾尝试了: @RequestMapping(value="/user/register") public ModelAndView toRegister( Integer flag, User user, MultipartHttpServletRequest request,// MultipartFile file, ModelAndVi