1

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?

informatik01
  • 16,038
  • 10
  • 74
  • 104
Grim
  • 1,938
  • 10
  • 56
  • 123
  • I'm not aware of a general API way to do this but it is relatively trivial to read the web.xml as a WAR resource. – McDowell Jun 02 '13 at 21:54

1 Answers1

2

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.

Community
  • 1
  • 1
Simon Curd
  • 790
  • 5
  • 12
  • I would argue that this does not answer the original question "How can I programmatically get the configured error.jsp?" The larger question in my mind is how can I programmatically access information from the `web.xml`. – raner Oct 23 '19 at 01:32