Hiddenhttpmethodfilter and Multipart/form-data of Spring MVC

Source: Internet
Author: User

A strange thing about the Servletrequest.getparameter () method was found today.

If the enctype of the form form is application/x-www-form-urlencoded (the value is a default value and does not need to be explicitly declared), then in the filter or servlet, We can get the corresponding parameter value directly through Request.getparameter (), if the form form's enctype is multipart/form-data (the upload image needs to declare the value), if no additional code is used to parse the input stream, In a filter or servlet, calling Request.getparameter () returns NULL.

The Hiddenhttpmethodfilter class of Spring MVC obtains the enhanced HTTP method by invoking Request.getparameter ("_method") in the Dofilterinternal () method. such as Patch,delete. However, if the enctype of the submitted form is Multipart/form-data, the Request.getparameter ("_") is invoked in the Hiddenhttpmethodfilter dofilterinternal () method. Method "), returns NULL, and an error occurs.

Two ways to solve this problem:

1. If the form's enctype is multipart/form-data, the form should not contain <input type= "hidden" name= "_method"/>, and vice versa.

2, before the request arrives hiddenhttpmethodfilter, resolves the form, and wraps the request, so that in Hiddenhttpmethodfilter dofilterinternal () Call Request.getparameter ("_method") in the method returns the correct value.

To supplement the class associated with this issue: Multipartfilter

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.