Struts2配置文件通配符的使用

Struts2配置文件中使用通配符收藏

形式一:调用相同Action中的不同方法

<action name="*Action" method="{1}" class="com.system.web.action.LoginAction">
	<result name="input">/login.jsp</result>
	<result name="success">/welcom.jsp</result>
	<result name="error">/error.jsp</result>
</action>	


其中表达式{1}的值为name属性值中第一个*的值

如果用户请求的URL为loginAction.action,则调用com.system.web.action.LoginAction中的login方法

如果用户请求的URL为registerAction.action,则调用com.system.web.action.LoginAction中的register方法

 

形式二:调用不同Action中的execute方法

<action name="*Action" class="com.system.web.action.{1}Action">
	<result name="input">/login.jsp</result>
	<result name="success">/welcom.jsp</result>
	<result name="error">/error.jsp</result>
</action>	


上面没有出现method属性,故默认调用对应action的execute方法

如果用户请求的URL为LoginAction.action,则调用com.system.web.action.LoginAction中的execute方法

如果用户请求的URL为RegisterAction.action,则调用com.system.web.action.RegisterAction中的execute方法

 

形式三:动态结果

 

<action name="FlowMonitor_*" method="{1}" class="com.monitor.web.action.FlowMonitorAction">
	<result name="init">/pages/monitor/flowMonitor.jsp</result>
	<result name="table">/pages/monitor/flowMonitorBigTable.jsp</result>
	<result>/{1}.jsp</result>
</action>

当处理结果是init时,会转到/pages/monitor/flowMonitor.jsp

当处理结果是success时,如果FlowMonitor_Query.action,则会执行FlowMonitorAction中的Query方法,并且跳转到/Query.jsp页面;

如果FlowMonitor_delete.action,则会执行FlowMonitorAction中的delete方法,并且跳转到/delete.jsp页面

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值