Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding conditions in web.xml

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.

like image 690
Suresh Atta Avatar asked Jun 11 '13 11:06

Suresh Atta


2 Answers

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.

like image 112
AlexR Avatar answered Sep 28 '22 09:09

AlexR


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>
like image 25
Vsevolod Golovanov Avatar answered Sep 28 '22 08:09

Vsevolod Golovanov