I get a 415 error when submitting the form.
Front page:
<h2>consumes属性</h2>
<form action="user/addUser" method="post">
<input type="submit" value="normal form submission">
</form>
Backend controller:
@RequestMapping(value="/addUser",
method=RequestMethod.POST,
consumes="application/json")
public String addUser() {
return "success";
}
The reason for the 415 error is: The submitted content type of the processing request does not match.
Here, the browser's native <form> form, if the
enctype
attribute is not set, will eventually
submit data in the form of
application/x-www-form-urlencoded .
Change the background controller to:
@RequestMapping(value="/addUser",
method=RequestMethod.POST,
consumes="
application/x-www-form-urlencoded
")
public String addUser() {
return "success";
}