javax.servlet.Se" /> javax.servlet.Se" /> javax.servlet.Se"/>

Programmatically get error-page from web.xml

764 Views Asked by At

I often have redirects like

r.sendRedirect("error.jsp"); 

Anyway the web.xml already defines error-pages.

<error-page>
    <exception-type>javax.servlet.ServletException</exception-type>
    <location>/error.jsp</location>
</error-page>

How can I programmatically get the configured error.jsp?

1

There are 1 best solutions below

1
Simon Curd On BEST ANSWER

The API provides methods to do this without explicitly specifying the error page in your code. See the answer to this question for an example: How do I throw a 404 error from within a java servlet?

The main benefit of the answer given is that the servlet container will ensure the correct HTTP error code is returned as part of the response.