Upload file by using SpringMVC CommonsMultipartResolver

Error Information:
HTTP Status 400 – Bad Request
The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).


Error Cause:
dispatcherServlet-servlet.xml

1
2
3
4
5
6
7
<!-- for uploading files -->
<!-- the id should be unique -->
<!-- error occurs -->
<bean id="commonsMultipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"></property>
</bean>

Why? Review class DispatcherServlet:

public static final String MULTIPART_RESOLVER_BEAN_NAME = "multipartResolver";
Pay more attention to other final variables.


Error Solution:

1
2
3
4
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"></property>
</bean>