java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.spri

java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest

严重: Servlet.service() for servlet [SpringMVC] in context with path [/smarthome] threw exception
java.lang.ClassCastException: org.apache.catalina.connector.RequestFacade cannot be cast to org.springframework.web.multipart.MultipartHttpServletRequest
	at com.wanyu.frame.base.AuthFilter.doFilter(AuthFilter.java:55)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:509)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1104)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1524)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1480)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
我的错误是在 filter 中发生的,目前还不清楚为什么。

在 Controller 中是没有问题的。


其它相关原因:

1、如果没有提交或者有人访问这个恶意请求不带文件,spring就会抛出错误 。

2、jsp页面的表单没有设置 enctype="multipart/form-data"。

此处有个重点:一定要是method="post",如果没有定义请求方式,也一定会转化出错!!!

<form action="" method="post"  enctype="multipart/form-data">  
3、 springMvc中没有配置文件上传:

<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>   
        <property name="defaultEncoding">  
            <value>utf-8</value>  
        </property>  
</bean>   
4、必要的jar包没有导入。

5、如果你上边的都没有问题,那么就是你只用了一个浏览器在测试,要清除缓存!!对,没有错,缓存!!


你可能感兴趣的:(java,servlet,filter,multipart)