春:状态405.请求方法 'POST' 不支持
问题描述:
我从形式发送到春:状态405.请求方法 'POST' 不支持
<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 - 请求方法 'POST' 不支持的。
为什么呢?我发送post request
和控制器有一个post方法是不是?
答
在Spring-security.xml中<csrf />
:Spring Security Cross Site Request Forgery(CSRF)保护会阻止它。
令牌需要通过POST请求与表单一起使用。
在表单中添加以下内容:
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
+1
不是'spring-sequrity.xml',而是在页面的'form'中 – thinker
贵'GET'工作? – timothyclifford
@timothyclifford是的,它的工作原理 – thinker
当你的应用程序启动时,你能看到映射到日志中的POST路由吗? – timothyclifford