I am trying to submit a form to a controller. On the page this is simply:
code
<form action="http://localhost:8080/form/submit" method="post">
<button type="submit">Submit</button>
</form>
code
On the controller I have the following handler:
code
@RequestMapping(value = "/form/submit", method = RequestMethod.POST, produces = MediaType.APPLICATION_XHTML_XML_VALUE)
@ResponseBody
public String submitForm(HttpServletRequest request) {
String baseUrl = getBaseUrl(request);
TestForm testForm = new TestForm();
log.info("form submitted");
return formService.generate("test", baseUrl, testForm);
}
code
When I submit the form it gives me a 404 not found error. Yet if I change this to GET instead of POST it works fine.
I am using Spring Security where I have allowed requests to this controller.
code
.antMatchers("/form/**").authenticated()
code
Is there any reason why this would work for GET but not POST?