• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regarding Exception and Error Handling

 
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Could you please tell me how to redirect to exception page or error page in spring while getting Exception or Error like 404, 500 error.

Thanks,
Santhosh Kumar V.K
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could define an @ExceptionHandler that catches certain types of exception and returns whatever view (error page you felt like). If you wanted that to apply to all controllers you could put in in a class annotated with @ControllerAdvice.

See more on that here:
http://docs.spring.io/spring/docs/3.2.4.RELEASE/spring-framework-reference/html/mvc.html#mvc-ann-exceptionhandler


If you are asking for an exception that is caught by the container you can define error pages in your web.xml for certain status codes. However this approach is not unique to Spring. In this case you would just make sure that URL defined in your web.xml maps to a controller that returns an error page. It really just depends how far you want to propagate the exception. For exceptions like forbidden or not found (403, 404) the web.xml approach probably makes more sense since the request is actually rejected before you even get inside of a Spring Controller.
 
reply
    Bookmark Topic Watch Topic
  • New Topic