Spring:状态405.请求方法' POST'不支持

时间:2016-12-17 13:06:19

标签: spring spring-mvc http-status-code-405

我从表单发送动作

<form name='recoverForm' action="<c:url value='recover'/>" method='POST'>

弹簧:

@Controller
@RequestMapping(value = "recover")
public class RecoverController {

    @RequestMapping(method = RequestMethod.GET)
    public String recoverPage(Map<String, Object> model) {
        return "recover"; //this works
    }

    @RequestMapping(method = RequestMethod.POST)
    public String recover(Map<String, Object> model) {
        System.out.println("_____________recover in action");
        return "home"; //error 405
    }

但我收到错误405 - 请求方法&#39; POST&#39;不支持。

enter image description here

为什么?我发送post request并且控制器有一个post方法不是吗?

1 个答案:

答案 0 :(得分:0)

在Spring-security.xml <csrf />中:Spring Security Cross Site Request Forgery(CSRF)保护阻止它。

通过POST请求表单需要令牌。

在表单中添加以下内容:

<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>