0

Is it possible to save yourself a lot of work by dynamically pass an exception type (or error code) in web.xml instead of "classic" hardcoding?

For example use something similar to <exception-type>*</exception-type> instead of <exception-type>SomeException</exception-type> and then use sth similar to <location>/MyServlet?exctype=$exception-type$</location> instead of <location>/MyServlet</location> (or <location>/MyServlet?exctype=SomeException</location>)?

And/or similarly for <error-code>?

/* Below isn't correct web.xml syntax and will not work but is a sketch of what I am looking for. */
<error-page>
    <exception-type>*</exception-type>
    <location>/MyServlet?exctype=$exception-type$</location>
</error-page>
<error-page>
    <error-code>*</error-code>
    <location>/MyOtherServlet?errcode=$error-code$</location>
</error-page>
xyzt
  • 59
  • 6
  • Why would you want to do this? –  Nov 19 '19 at 10:21
  • I wanted (distinguishing between runtime and develop-time) to make dynamic error pages based on one servlet. There are many errors and exceptions. In runtime it would display the error code for any technical support request (saying nothing to the user) and in develop-time a full description of the HTTP error or exception details. – xyzt Nov 19 '19 at 10:53
  • No, why don't you just extract the exception type or error code in the servlet itself? Why must it end up in the URL? – BalusC Nov 19 '19 at 10:54
  • Servlet can recognize parameter[s] (eg. error code). But how to pass this error code to servlet without multiplying entries in web.xml? – xyzt Nov 19 '19 at 11:01
  • It's already available as a [request attribute](https://stackoverflow.com/q/12257928/). So this means that you didn't knew it and that this is actually the answer to the X problem you had in your apparent [XY-problem](http://xyproblem.info)? – BalusC Nov 19 '19 at 11:29
  • After a closer look at the example you indicated, I made a dispatcher passing data to JSP and after simple corrections to this JSP everything works. Thanks for the guidance. – xyzt Nov 20 '19 at 07:53

0 Answers0