I have a Spring controller which is being called from JQuery.post(). When it is called the controller\'s method is invoked and returns. But then, in the background, Spring c
I believe if you have a null or void return type, Spring will try to resolve the view based on the request URL. I think the proper form here would be to simply return an OK page, since this doesn't appear to be JSON or anything like that. Or, just tag it with @ResponseBody and return an empty string.
Solved.
The problem was as #CodeChimp suggested, except I still wanted a void return type.
I added the @ResponseBody
to the addPerson
method and everything worked fine:
@RequestMapping(value="put", method = RequestMethod.POST)
**@ResponseBody**
public void addPerson(@ModelAttribute("person") Person person){
System.out.println(">>>>>>> person: " + person);
System.out.println(">>>>>>>>> " + person.getFirstName());
people.add(person);
}
The clue came from http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/mvc.html#mvc-ann-responsebody. Although the documentation is not clear what happens with a void return. Just tried it and it worked.