开发者

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

开发者 https://www.devze.com 2023-02-08 11:11 出处:网络
I\'m trying to route these two url\'s to different Actions.We are using Struts 1.2: /abc-def/products /abc-def

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="/开发者_如何学Cabc*" 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消