struts2 —— 通配符

struts2 通过通配符的使用可以大大简化其配置文件。其在配置文件中的使用形式如下:


[b]一、调用相同Action中的不同方法:[/b]

<action name="*Action" class="Test.LoginRegistAction" method="{1}" >
<result name="input"> /login.jsp </result>
<result name="success"> /welcome.jsp </result>
<result name="error"> /error.jsp </result>
</action>


[b]表达式{1}的值为 name属性值中的第一个*的值。[/b]
eg: 如果用户请求的URL为 loginAction.action 则调用Test.LoginRegistAction 中的 login 方法;
如果用户请求的URL为registAction.action 则调用Test.LoginRegistAction 中的 regist 方法;
[b]二、调用不同action的execute方法[/b]

<action name="*Action" class="Test.{1}Action" >
<result name="input"> /login.jsp </result>
<result name="success"> /welcome.jsp </result>
<result name="error"> /error.jsp </result>
</action>


[b]由于上面没有 method 属性 所以调用execute方法;[/b]
eg: 如果用户请求的URL为 LoginAction.action 则调用Test.LoginAction 中的 execute方法;
如果用户请求的URL为RegistAction.action 则调用Test.RegistAction 中的 execute方法;

[b]三、动态结果[/b]

<action name="*Action" class="Test.LoginRegistAction" method="{1}" >
<result name="input"> /login.jsp </result>
<result > /{1}.jsp </result>
</action>

当处理结果为 input时 转到 login.jsp;
当处理结果为 success时 转到 success.jsp;
当处理结果为 error时 转到 error.jsp;
method属性中的通配符同上。

转自 :
[url]http://wenku.baidu.com/view/067186778e9951e79b892706.html[/url]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值