I'm having a little trouble sending form data as a JSON, and handling it with the controller. What is the "best" way to approach this, using spring annotations?
My hope was that I could send the form data to the controller as an object, and have the controller map it to the model automatically, but im receiving an error
The server refused this request because the request entity is in a format not supported by the requested resource for the requested method.
Form
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP JSON</title>
</head>
<body>
<h2>Please enter name below to register</h2>
<br>
<h1>User Name</h1>
<form method="post" action="/SpringRedirecting/process/" enctype="application/json">
<br>
<input type="text" name="uname" value="" />
<br>
<input type="text" name="password" value="" />
<br>
<input type="submit" value="Submit" />
</form>
</body>
Controller
@RequestMapping(method = RequestMethod.POST, consumes = "application/json")
public String processRequest(@RequestBody final User user, ModelMap map, HttpServletRequest req){
map.addAttribute("user", user);
return "output";
}
Aucun commentaire:
Enregistrer un commentaire