Struts2的Result类型

Struts2 result类型

 

1.dispatcher:服务器跳转到页面,通常来处理JSP,默认类型。


2.redirect:重定向到页面。

Action:

1 public String redirect() {  
2         message = "message中有值";  
3         return "redirect";  
4 }  
struts.xml

1 <package name="chapter3" namespace="/chapter3" extends="struts-default">  
2         <action name="redirectAction" class="action.Chapter3Action" method="redirect">  
3             <result name="redirect" type="redirect">/redirect.jsp</result>  
4         </action>  
5 </package>

注意的地方:外部中转不能带值过去,并且页面不能受保护

传参数:

1 <action name="redirectAction" class="action.Chapter3Action" method="redirect">  
2     <result name="redirect" type="redirect">/redirect.jsp?message=${message}</result>  
3 </action> 

 页面:

${param.message}<br>

 

3.chain:服务端跳转到Action;

action:

1 public String action2() {  
2     message = "我是action2中设置的值";  
3     return "action2";  
4 }  
struts.xml

1 <package name="chapter32" namespace="/chapter32" extends="struts-default">  
2     <action name="action2" class="chapter3.action.Chapter3Action" method="action2">  
3         <result name="action2" type="chain">  
4             <param name="actionName">redirectAction</param>  
5             <param name="namespace">/chapter3</param>  
6         </result>  
7     </action>  
8 </package> 
4.redirectAction:外部跳转到Action;

action:

1 public String action3() {  
2     message = "我是action3中设置的值";  
3     return "action3";  
4 }  
struts.xml

1 <action name="action3" class="chapter3.action.Chapter3Action" method="action3">  
2     <result name="action3" type="redirectAction">redirectAction</result>  
3 </action>  
注:还有很多result类型,这里就简单的介绍了Struts2常用的类型。





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值