Spring: Status 405. Request method 'POST' not supported

2k views Asked by At

I send from form an action to

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

spring:

@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
    }

But I get error 405 - Request method 'POST' not supported.

enter image description here

Why is it? i send post request and controller has a post method is not it?

1

There are 1 answers

1
David On BEST ANSWER

In Spring-security.xml <csrf /> : Spring Security Cross Site Request Forgery (CSRF) protection blocks it.

Token required along with form via POST request.

In form add the following:

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