Getting "405 - Request method 'GET' not supported when calling" method=DELETE
Solution 1
Forms can be submitted via GET
or POST
only (maybe also PUT
, but I doubt that is widely implemented), as form submission requires a method where data is transmitted to the server.
The DELETE
method does not have a request body, so specifying it in a form action is unsupported.
Solution 2
Do you have the HiddenHttpMethodFilter filter in your 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>
Solution 3
The error messages indicate that the browser is actually sending a GET request rather than a DELETE request.
What you need to do is:
examine the source of the web page that the browser is on at the time, and
using the browser's web debugger, see what the request URL and method actually are.
Related videos on Youtube
Comments
-
Pete almost 2 years
I have a Spring MVC web app. In it a form with a button that's supposed to delete a resource from another resource:
<td> <form action="/product-bases/${productBase.id}/positions/${position.id}" method="DELETE"> <input type="submit" value="delete" /> </form> </td>
My controller:
@Controller @RequestMapping(value = "/product-bases/{id}/positions") public class ProductBasePositionController { @RequestMapping(value = "/{positionId}", method = RequestMethod.DELETE) public ModelAndView delete(@PathVariable Integer productBaseId, @PathVariable Integer positionId) {
So in theory the server should route to the controller. But alas it does not, hence the post ;)
I'm getting
HTTP Status 405 - Request method 'GET' not supported type Status report message Request method 'GET' not supported description The specified HTTP method is not allowed for the requested resource (Request method 'GET' not supported). Apache Tomcat/7.0.19
Obviously I don't have a get for /positions/id defined yet, but why should I, I want to do a delete for now..
(I'm also trying to run this from my spring-test-mvc framework on a mock servlet without any tomcat implementation in between and it gives me a 400 - bad request.. )
So what am I missing here?
Oh, just to cut some corners: post and get will work for other resources, so the rest of my setup is fine.
The booting server even tells me:
RequestMappingHandlerMapping [INFO] Mapped "{[/product-bases/{id}/positions/{positionId}],methods=[DELETE],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView our.view.controller.ProductBasePositionController.delete(java.lang.Integer,java.lang.Integer)
Anyone as confused as I am? If less so, please enlighten me!
-
Julian Reschke almost 12 yearsAlmost. Browsers only support GET and POST for now, thus silently change the method to GET when it's unsupported.
-
Pete almost 12 yearsWow, I didn't know that.. So my only option seems to put a hidden input field in the form that says name=method value=delete? Apart from javascrip I mean.. Since I can't send a delete via link either.. Seems kind of strange and makes any attempt to develop truly RESTful impossible?!
-
Julian Reschke almost 12 yearsPete: see w3.org/html/wg/tracker/issues/195. You may want to join the HTML WG. See w3.org/html/wg for details.
-
Pete almost 12 yearsah, that sounds promising too, will try on monday.. Thanks!
-
Pete almost 12 yearsUnfortunately we can't use the filter trick, because then it won't be testable anymore as we're using spring-test-mvc which does not support filters.