Hiddenhttpmethodfilter and Enctype= "multipart/form-data" conflict

Source: Internet
Author: User
Tags file upload

Recently in the background of a website, but related to the implementation of the editing function, due to the implementation of the file upload function, it is necessary to introduce enctype= "multipart/form-data" in form form, but after introduction, the program runs to show errors, Get Method.patch, even though I have added <input type= "hidden" name= "_method" value= "PATCH" in the form form; Added Hiddenhttpmethodfilter to the Web. xml file, the page shows post not supported, but I replaced the patch with the original post without problems, so I found out that the problem was when introducing enctype= "multipart /form-data ", Hiddenhttpmethodfilter inside the Request.getparam get not value, find a lot of information on the Internet, there are others encounter this problem, the final solution is

1. In controller incoming @requestparam (value = "Avatarimage") multipartfile avatarimage the Type field to accept the upload file in form form

2. Add <filter> before Hiddenhttpmethodfilter
<filter-name>multipartFilter</filter-name>
<filter-class>org.springframework.web.multipart.support.multipartfilter
</filter-class>
<init-param>
<param-name>multipartResolverBeanName</param-name>
<param-value>multipartResolver</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>multipartFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> a layer of packaging for the request, after which you can get the value of the request

This finally solved my problem, but I am not very clear about the principle behind, hope to understand thoroughly, can share with me.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.