I'm trying to use RequestMethod.PUT and RequestMethod.DELETE in Spring MVC controller. My controller has a @RequestMapping for PUT and DELETE, but despite that, I'm getting error when trying to use it:
Request method 'GET'/'POST' not supported
Controller:
@RequestMapping(value = "/admin/user/{id}", method = RequestMethod.PUT)
public ModelAndView updateUser(HttpServletRequest request, HttpServletResponse response, @ModelAttribute("user") User user, @PathVariable long id) {
...
}
@RequestMapping(value = "/admin/user/delete/{id}", method = RequestMethod.DELETE)
public @ResponseBody ModelAndView deleteUser(HttpServletRequest request, HttpServletResponse response, @PathVariable long id) {
...
}
I've added also filters in web.xml
:
<filter>
<filter-name>httpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>httpMethodFilter</filter-name>
<servlet-name>springDispatcher</servlet-name>
</filter-mapping>
Spring form for PUT:
<form:form id="registerForm" method="put" action="${user.id}" modelAttribute="user" class="form-horizontal">
Generated HTML:
<form id="registerForm" class="form-horizontal" action="13" method="post"><input type="hidden" name="_method" value="put"/>
I know, that if browser isn't supporting PUT/DELETE then POST/GET is used, but why my controller method is not called?