Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top