The solution is configured as follows
<!--config file upload parser - <BeanID= "Multipartresolver"class= "Org.springframework.web.multipart.commons.CommonsMultipartResolver"> <!--Specifies that the total size of the uploaded file cannot exceed 20M. Note the limitations of the Maxuploadsize attribute are not for individual files, but for the sum of the capacity of all files - < Propertyname= "Maxuploadsize"value= "20000000"/> < Propertyname= "Defaultencoding"value= "Utf-8"></ Property> </Bean> <!--The above configuration is introduced in Web. XML, which is important! Only the beans under the contextconfiglocation configuration file will be loaded directly for the following filter calls - <Context-param> <Param-name>Contextconfiglocation</Param-name> <Param-value>Classpath:spring/root-context.xml</Param-value> </Context-param> <!--when there is a file in the form form, the filter can process the file in the HTTP request, the filter will be submitted by the Post method, and the form form should be set to Enctype= "Multipart/form-data" - <Filter> <Filter-name>Multipartfilter</Filter-name> <Filter-class>Org.springframework.web.multipart.support.MultipartFilter</Filter-class> <Init-param> <Param-name>Multipartresolverbeanname</Param-name> <!--parser configured in spring with ID multipartresolver - <Param-value>Multipartresolver</Param-value> </Init-param> </Filter> <filter-mapping> <Filter-name>Multipartfilter</Filter-name> <Url-pattern>/*</Url-pattern> </filter-mapping> <!--resolves the hidden name _method input in the form form and needs to be placed in Multipartfilter to find the corresponding controller in the corresponding put request method - <Filter> <Filter-name>Hiddenhttpmethodfilter</Filter-name> <Filter-class>Org.springframework.web.filter.HiddenHttpMethodFilter</Filter-class> </Filter> <filter-mapping> <Filter-name>Hiddenhttpmethodfilter</Filter-name> <Url-pattern>/*</Url-pattern> </filter-mapping>
The principle is that the filter is carried out one after the other, using Multipartfilter to process the file, in the form of hiddenhttpmethodfilter processing the hidden name of the _method input. Next Multipartfilter the value of the configured multipartresolverbeanname in the XML that is configured in Contextconfiglocation.
Org.springframework.web.multipart.support.MultipartFilter handles the file stream in the HTTP request and cannot resolve the _method parameter.
Org.springframework.web.filter.HiddenHttpMethodFilter can parse the hidden name _method input in the form form.
RESTful style, put modify function request, the form exists file error-http Status 405-request method ' POST ' not supported