1

I'm currently mapping error codes in web.xml and so far it looks like this:

  <error-page>
    <error-code>404</error-code>
    <location>/errorHandler?code=404</location>
  </error-page>
  <error-page>
    <error-code>500</error-code>
    <location>/errorHandler?code=500</location>
  </error-page>

Do I have to map every single error code manually or is there more automatic way? I'd like to have something like this:

  <error-page>
    <error-code>*</error-code>
    <location>/errorHandler?code=*</location>
  </error-page>
Saraph
  • 992
  • 1
  • 11
  • 25

1 Answers1

1

That's possible, according to the documentation of oracle. It depends on whether you are using servlet 2.5 (not supported) or 3.0 (supported).

I would recommend you to use plain html for the error codes. The reason behind this, is these pages will be shown when something is going very wrong. Full list of status codes

Generic solution example: moreinfo with onehippo

From security perspective it is not recommended to give information what went wrong in the application: https://blog.whitehatsec.com/error-handling-in-java-web-xml/

Jurrian Fahner
  • 349
  • 1
  • 11
  • Thanks to your last link I found out I can use `request.getAttribute("javax.servlet.error.status_code");` instead of passing error code value from `web.xml` and then remove `` tag completely. Great answer. – Saraph Jun 27 '15 at 23:34