【问题标题】:Spring: Status 405. Request method 'POST' not supportedSpring:状态 405。不支持请求方法“POST”
【发布时间】:2017-05-03 02:31:51
【问题描述】:

我从表单发送一个动作到

<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 方法不是吗?

【问题讨论】:

  • 你的GET 有用吗?
  • @timothyclifford 是的,它有效
  • 当你的应用启动时,你能在日志中看到被映射的 POST 路由吗?
  • @timothyclifford 不确定,你是什么意思
  • 你用的是什么版本的 Spring?

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


【解决方案1】:

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

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

在表单中添加以下内容:

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

【讨论】:

  • 不在`spring-sequrity.xml`中,但在页面中的form
猜你喜欢
  • 1970-01-01
  • 2012-06-24
  • 2015-05-01
  • 2015-04-09
  • 2016-03-29
  • 2014-09-24
  • 2013-04-09
  • 2012-04-20
  • 2015-09-02
相关资源
最近更新 更多