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