I am using Starbox in my Spring page. I want to submit the user rating so I can store it in the database and not have to refresh the page for the user. How can I have a Spring controller that accepts this value and doesn’t have to return a new view. I don’t necessarily need to return any updated html – if the user clicks the Starbox, that is all that needs to happen.
Similarly, if I have a form with a submit button and want to save the form values on submit but not necessarily send the user to a new page, how can I have a controller do that? I haven’t found a great Spring AJAX tutorial – any suggestions would be great.
The AJAX logic on the browser can simply ignore any data the server sends back, it shouldn’t matter what it responds with.
But if you really want to make sure no response body gets sent back, then there are things you can do. If using annotated controllers, you can give Spring a hint that you don’t want it to generate a response by adding the
HttpServletResponseparameter to your@RequestMappingmethod. You don’t have to use the response, but declaring it as a parameter tells Spring “I’m handling the response myself”, and nothing will be sent back.edit: OK, so you’re using old Spring 2.0-style controllers. If you read the javadoc on the Controller interface, you’ll see it says
So if you don’t want to render a view, then just return
nullfrom your controller, and no response body will be generated.