Usually you should create a new class that represents the form (this is called a form support object), for example, UserColorForm , which contains properties for each of the inputs in the request body.
Your controller method will look like this:
@RequestMapping(value = "/users/login", method = RequestMethod.POST) @ResponseBody public String handleLogin(UserColorForm form, ModelMap map) {
If the FBO bean has property names matching the input names of the form, Spring will associate the input to the request directly with the properties. those. if the form input is username=matt&color=blue , then Spring will create a new instance of my form and call setUsername("matt") and setColor("blue") .
By the way, you probably don't want the method to be annotated with @ResponseBody if you are going to return the view name from the method ( user.jsp ). @ResponseBody means that the return value of the method must be written directly to the response stream.
source share