In spring restful, when the browser does not support the put and delete transmission protocols, you can add a hidden field to the form. The hidden name attribute is: _ method, for example:
<Form action = "Update" method = "Post">... <input type = "hidden" name = "_ method" value = "put"/> </form>
However, the default method filter (Org. springframework. Web. Filter. hiddenhttpmethodfilter) in spring only judges the post transmission protocol.
Custom get support
Public class myhiddenhttpmethodfilter extends hiddenhttpmethodfilter {private string methodparam = default_method_param; Public void setmethodparam (string methodparam) {assert. hastext (methodparam, "'methodparam' must not be empty"); this. methodparam = methodparam;} @ overrideprotected void dofilterinternal (httpservletrequest request, httpservletresponse response, filterchain) throws servletexception, ioexception {string paramvalue = request. getparameter (methodparam); string _ method = request. getmethod (); If (stringutils. haslength (paramvalue) {string method = paramvalue. touppercase (locale. english); Boolean B = ("Post ". equals (_ method) & "put ". equalsignorecase (method) | ("get ". equals (_ method) & "delete ". inclusignorecase (method); If (B) {httpservletrequest wrapper = new httpmethodrequestwrapper (request, method); filterchain. dofilter (wrapper, response);} else {}} else {filterchain. dofilter (request, response) ;}} Private Static class httpmethodrequestwrapper extends httpservletrequestwrapper {private final string method; Public httpmethodrequestwrapper (httpservletrequest request, string method) {super (request); this. method = method ;}@ overridepublic string getmethod () {return this. method ;}}}
When the delete protocol is used, the request uses get and the parameter _ method = Delete is added. When the put protocol is used, the request uses post and then adds _ method = put.