views:

134

answers:

1

I have configured the SimpleMappingExceptionResolver in my web application, which is handling all the unexpected exceptions in the application and directing the user a to simple error page for recovery.

But what would be a best practice of handling an expected exception (more specifically: exception caused by hibernate optimistic concurrency control)?

I don't want the user to be directed to a new error page, but allow him/her to continue working in the same jsp page. What is the best method to achieve this?

+1  A: 

Assuming Spring 3, you can annotate methods on your Controller class with @ExceptionHandler to define what should happen when particular types of exceptions come out of your handler methods. The signature is not quite as flexible as @RequestMapping methods, but you can generally manage what you want. (Which in this case sounds like just add an error message to the model map and re-run the method that handles GET)

Affe
Just be mindful that you don't have an implicit map, if you have methods annotated with @ModelAttribute that you're using to populate it, you may need to manually rerun them depending on the View!
Affe