Can you use regular expressions in struts-config.xml?

992 views Asked by At

I'm trying to route these two url's to different Actions. We are using Struts 1.2:
/abc-def/products
/abc-def

I tried putting this action first:

<action path="/abc*/products" type="com.business.exampleAction">
    <forward name="success" path="/go"/>
</action>

and then this one after:

<action path="/abc*" type="com.business.differentExampleAction">
    <forward name="success" path="/goElsewhere"/>
</action>

but it always goes to the second action (differentExampleAction in this case). I've tried various iterations for the *, like .* or (.*), but haven't found anything that actually works yet.

From what I've read, it seems like the only regular-expression-like characters allowed in struts-config are the wildcard symbols (* and **), but I hope I am wrong.

1

There are 1 answers

1
limc On

Unfortunately, you are correct about the wildcard in Struts 1.x... you cannot have anything after *. See documentation section 4.10. This is one of many limitations of Struts 1.x... granted, it is one of the first Java MVC frameworks that works (obviously with some kinks now), which is the reason I decided to switch to Spring MVC 3.x because it allows me to do more Rest-like URI, for example:

/abc/product/{productId}/part/{partId}

I just don't see how this can be easily accomplished in Struts 1.x.