简体   繁体   中英

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?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM