2
votes

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
Does your GET work? - timothyclifford
@timothyclifford yes, it works - thinker
When your app is starting, can you see the POST route being mapped in the log? - timothyclifford
@timothyclifford not sure, what do you mean - thinker
what version of Spring are you using? - timothyclifford

1 Answers

0
votes

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}"/>