Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request method 'POST' not supported

According to the Spring Documentation here:

While HTTP defines these four methods, HTML only supports two: GET and POST. Fortunately, there are two possible workarounds: you can either use JavaScript to do your PUT or DELETE, or simply do a POST with the 'real' method as an additional parameter (modeled as a hidden input field in an HTML form).

They have done the latter, and can be achieved with the following spring MVC form tag:

<form:form method="delete">
   <input type="submit" value="Delete"/>
</form:form>

The problem is when i click 'Delete' my page throws the following error:

HTTP Status 405 - Request method 'POST' not supported

I changed the debug level of org.springframework.web to debug and found the following message:

DEBUG AnnotationMethodHandlerExceptionResolver - Resolving exception from handler [foo.bar.MessageForm@da9246]:
org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported

I used RestClient with DELETE method and the method is called as expected. What am I doing wrong here?

like image 887
Joopiter Avatar asked Nov 04 '10 03:11

Joopiter


People also ask

How do I fix HTTP method POST is not supported by this URL?

Solution: Use only the form button you mapped to your servlet action. Show activity on this post. If you're still facing the issue even after replacing doGet() with doPost() and changing the form method="post" . Try clearing the cache of the browser or hit the URL in another browser or incognito/private mode.


1 Answers

You need to configure HiddenHttpMethodFilter in your web.xml

Details can be found here:

like image 116
maximdim Avatar answered Oct 12 '22 03:10

maximdim