SPRINGMVC (eight) requestmapping Hiddenhttpmethodfilter

Source: Internet
Author: User

Springmvc Hidden methods:

Use the Put and delete methods. The default HTML supports the Get and post methods. Turn post into put and delete methods via Hiddenhttpmethodfilter.

1. Configure Hiddenhttpmethodfilter to Web. xml

    <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>    

2. Controller code

 Packagecom.tiekui.springmvc.handlers;ImportOrg.springframework.stereotype.Controller;Importorg.springframework.web.bind.annotation.PathVariable;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.bind.annotation.RequestMethod;ImportOrg.springframework.web.bind.annotation.RequestParam; @Controller Public classhiddenhttpmethodfiltertest {@RequestMapping (value= "Testhiddenhttpmethod/{id}", method=requestmethod.delete) PublicString Testhiddenhttpmethoddelete (@PathVariable ("id") (Integer ID) {SYSTEM.OUT.PRINTLN ("Delete" +ID); return"Success"; } @RequestMapping (Value= "Testhiddenhttpmethod/{id}", method=requestmethod.put) PublicString Testhiddenhttpmethodput (@PathVariable ("id") (Integer ID) {SYSTEM.OUT.PRINTLN ("PUT" +ID); return"Success"; }    }

3. View Code

    <form action= "TESTHIDDENHTTPMETHOD/1" method= "POST" >        <input type= "hidden"  name= "_method" value= " PUT ">        <input type=" Submit "value=" Testhiddenhttpmethodput ">    </form>    <br>    <form action= "TESTHIDDENHTTPMETHOD/1" method= "POST" >        <input type= "hidden"  name= "_method" value= " DELETE ">        <input type=" Submit "value=" Testhiddenhttpmethoddelete ">    </form>

SPRINGMVC (eight) requestmapping Hiddenhttpmethodfilter

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.