I am trying to go to the error page if an exception occurs. For this, I defined:
<error-page> <error-code>500</error-code> <location>/error.jspx</location> </error-page>
in web.xml . I also tried to do this using Servlet:
<servlet> <servlet-name>ErrorHandler</servlet-name> <servlet-class>web.servlet.ErrorHandler</servlet-class> </servlet> <servlet-mapping> <servlet-name>ErrorHandler</servlet-name> <url-pattern>/errorhandler</url-pattern> </servlet-mapping> <error-page> <error-code>500</error-code> <location>/errorhandler</location> </error-page>
But none of them are related to calling error.jspx and ErrorHandler Servlet.
To check for error handling, I tried to throw new Exception("Test"); from both managed bean constructors, as well as from actionListener . But it prints an exception in the console, but the redirection does not occur.
I also tried: <exception-type>java.lang.Exception</exception-type> instead of <error-code>500</error-code> , but no luck. How can I call a Servlet or go to a page whenever an exception occurs from anywhere, such as a constructor or any of the action / actionListener ?
source share