RESTful style, put modify function request, the form exists file error-http Status 405-request method ' POST ' not supported

Source: Internet
Author: User

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

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.