Wildcard-3

Parameters in namespaces

From Struts 2.1+ namespace patterns can be extracted as request parameters and bound to the action. To enable this feature, set the following constant in struts.xml:

<constant name="struts.patternMatcher" value="namedVariable"/>

With that in place, namespace definitions can contain {PARAM_NAME} patterns which will be evaluated against the request URL and extracted as parameters, for example:

@Namespace{"/users/{userID}");
public class DetailsAction exends ActionSupport {
  private Long userID;
  public void setUserID(Long userID) {...}
}

If the request URL is /users/10/detail, then the DetailsAction will be executed and its userID field will be set to 10.

Only one PatternMatcher implementation can be used at a time. The two implementations included with Struts 2 are mutually exclusive. You cannot use Wildcards and Named Variable patterns at the same application (if that were required, you'd need to create a custom PatternMatcher implementation).

Some tags tags not are 100% compatible with variables in the namespace. For instance, they may write the literal namespace into the HTML (eg /{user}/2w) instead of the path used in the request (ie. /brett/24). This usually affects attributes that attempt to guess the namespace of an action (eg. Form tag, Action tag, action=). This problem can be avoided by using HTML tags directly with relative paths or explicit URLs.

Similar functionality can also be implemented using a custom ActionMapper. The ActionMapper will need to parse the namespace and request itself to set parameters on the matched action. The default ActonMapper is responsible for invoking the PatternMatcher.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值