2013年8月23日

Exception handling in Spring MVC

Just very rough notes for handling exceptions in Spring MVC/Servlet

1. Servlet:
<error-page> ==> *.jsp/servlet (hard to use spring mvc classes)
or
<error-page> ==> spring mvc controller (fail if spring failed)

ps: in Servlet 3, one can set default page for all exceptions/status codes

Ref:
http://blog.csdn.net/c5153000/article/details/6236815
http://kahimyang.info/kauswagan/howto_blogs/997-custom_error_pages_for_tomcat_jsf_applications
http://stackoverflow.com/questions/2748220/how-to-show-user-friendly-error-page-instead-of-tomcat-log-with-stack-trace-in-b
http://blog.newsplore.com/2010/08/04/restful-error-handling-with-tomcat-springmvc
http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/mvc.html#mvc-ann-customer-servlet-container-error-page
http://stackoverflow.com/questions/995248/how-to-get-the-message-in-a-custom-error-page-tomcat


2. Spring MVC:
Use @ExceptionHandler (must set for each controller)
or
@ContollerAdvice (3.2 only)
or
HandlerExceptionResover (need to set and implement yourself)

Ref:
http://stackoverflow.com/questions/3230358/spring-3-create-exceptionhandler-for-nosuchrequesthandlingmethodexception
http://fuliang.iteye.com/blog/947191
http://www.stormpath.com/blog/spring-mvc-rest-exception-handling-best-practices-part-2

3. hybrid
Use 2 for spring mvc and 1 for the rest. View can be shared(JSP)

沒有留言:

張貼留言