Adding conditions in web.xml
Asked Answered
O

3

6

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.

Opinion answered 11/6, 2013 at 11:45 Comment(0)
G
3

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.

Guardafui answered 11/6, 2013 at 11:51 Comment(1)
several versions of your web.xml will do this.Because there are serveral changes like this.Thanks.Opinion
B
1

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>
Beep answered 30/9, 2015 at 11:18 Comment(0)
D
0

You can use if statements in error or location page. web.xml doesn't support if statements.

//error page
if("blog".equals(url))
    blog content ......
else if("profile".equals(url))
    profile content ......
Disservice answered 2/1, 2018 at 6:16 Comment(1)
// error page if("blog".equals(url)) blog content ...... else if("profile".equals(url)) profile content ......Disservice

© 2022 - 2024 — McMap. All rights reserved.