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?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top