user353283
user353283

Reputation:

Handling Exception like validation errors in Spring MVC

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?

Upvotes: 2

Views: 1861

Answers (1)

Affe
Affe

Reputation: 47994

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)

Upvotes: 1

Related Questions