Monday, 18 July 2016

How to return errors from servlet ?


Return HTTP error from Servlet using :
  • HttpServletResponse.sendError
  • HttpServletResponse.setStatus

Error pages declaration
We can defines a list of error page descriptions in web.xml mapped with status code or exception.
A specific error page can be returned in case of servlet sets a status code or throws a Java exception.

In case of status code set in response or exception (Runtime exceptions, ServletExceptions or IOExceptions) is thrown, container consults the list of status-code or exception-type elements under error page declarations and attempts a match.
If there is a match, it returns the resource declared as location entry.


No comments:

Post a Comment

Note: only a member of this blog may post a comment.