The browser form table only supports get and post requests, while the delete, put, and other methods are not supported, spring3.0 adds a filter that can convert these requests to a standard HTTP method, which enables the get, POST, put, and delete requests to be supported. The filter is hiddenhttpmethodfilter.
The parent class of Hiddenhttpmethodfilter is Onceperrequestfilter, which inherits the Dofilterinternal method of the parent class. It works by converting the value of the method property of the form form of a JSP page into a standard HTTP method, that is, get, POST, HEAD, OPTIONS, PUT, DELETE, TRACE, in the Dofilterinternal method. Then find the corresponding method in the controller. For example, when using annotations we may use the Controller for @requestmapping (value = "List", method = Requestmethod.put), so if you use <form method in your form = "Put", then the form will be submitted to the method labeled Method= "put".
It is important to note that because the Dofilterinternal method only filters the form that is a post, the following settings must be set on the page:
[Java]View Plaincopy
- <form action= "..." method="POST" >
- <input type="hidden" name="_method" value="put"/>
- ......
- </form>
Instead of using:
[Java]View Plaincopy
- <form action= "..." method="put" >
- ......
- </form>
At the same time, hiddenhttpmethodfilter must act before dispatcher, so when configuring Hiddenhttpmethodfilter in Web. XML, refer to the following code:
[Java]View Plaincopy
- <filter>
- <filter-name>HiddenHttpMethodFilter</filter-name>
- <filter-class>org.springframework.web.filter.hiddenhttpmethodfilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>HiddenHttpMethodFilter</filter-name>
- <servlet-name>spring</servlet-name>
- </filter-mapping>
- <servlet>
- <servlet-name>spring</servlet-name>
- <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class>
- <init-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>classpath:dispatcher.xml</param-value>
- </init-param>
- Lt;/servlet>
- <servlet-mapping>
- <servlet-name>spring</servlet-name>
- <url-pattern>*.html</url-pattern>
- Lt;/servlet-mapping>
Similarly, as filter, you can configure the Hiddenhttpmethodfilter parameter in Web. XML, the configurable parameter is Methodparam, and the value must be get, POST, HEAD, OPTIONS, PUT, DELETE, One of the trace. This will be a good solution to the put and delete method problems. In the ointment is to add a hidden fileds, some bad small.
Reprint Please specify: http://www.xujin.org or http://www.virgocloud.com
Spring3.0 after->spring MVC filter-hiddenhttpmethodfilter