This is a part of my web.xml
<error-page>
<error-code>500</error-code>
<location>/index</location>
</error-page>
Is there any way to tell to web.xml file that in development mode :
<location>/displayException</location>
for the above location property
?
or any way to add condition through code ?
Purpose of trying to do this is: In development mode I want to see the exception in page and in live mode I want to redirect him to default page when an exception occured.
You cannot do it in web.xml
level. This could be a cool feature if web.xml
respect system properties but it does not.
So you only way is to do this in code. Fortunately you have various possibilities. You can map your error URL to JSP where you implement logic based on system property or other parameter stored in property file, DB or where you want. You can do it in HTTP filter as well.
You can also create several versions of your web.xml: one for production, other for tests. If you want to avoid duplications create these versions using automatic generation from template.
In Wildfly there is a non-portable way to enable system properties evaluation in web.xml (and others, like persistence.xml). To do this specify the following in your server configuration (standalone.xml or other), in the ee
subsystem:
<subsystem xmlns="urn:jboss:domain:ee:2.0">
<spec-descriptor-property-replacement>true</spec-descriptor-property-replacement>
<!-- ... -->
</subsystem>
Then you could do things like this:
<location>${myapp.errorpage.location}</location>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With