开发者

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 j开发者_运维问答sp 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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜