可以在struts-config.xml中使用正则表达式吗?
我正在尝试将这两个网址路由到不同的操作。我们正在使用 Struts 1.2:
/abc-def/产品
/abc-def
我尝试将这个操作放在第一个:
<action path="/abc*/products" type="com.business.exampleAction">
<forward name="success" path="/go"/>
</action>
然后是这个操作:
<action path="/abc*" type="com.business.differentExampleAction">
<forward name="success" path="/goElsewhere"/>
</action>
但它总是转到第二个操作(在本例中为 differentExampleAction)。 我已经尝试了 * 的各种迭代,例如 .* 或 (.*),但还没有找到任何实际有效的东西。
根据我的阅读,struts-config 中唯一允许的类似正则表达式的字符似乎是通配符(* 和 **),但我希望我是错的。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不幸的是,您对 Struts 1.x 中的通配符的看法是正确的...
*
之后不能有任何内容。请参阅文档第 4.10 节。这是 Struts 1.x 的众多限制之一......当然,它是第一个可用的 Java MVC 框架之一(显然现在有一些问题),这就是我决定切换到 Spring MVC 3.x 的原因,因为它允许我做更多类似 Rest 的 URI,例如:我只是不明白如何在 Struts 1.x 中轻松实现这一点。
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:I just don't see how this can be easily accomplished in Struts 1.x.