struts2 重定向

本文介绍了Struts2框架中的重定向机制,并对比了Struts1的实现方式。重点讲解了如何通过配置struts.xml文件来实现不同类型的重定向。

struts2 重定向

struts2 的重定向和struts1 在使用方法上有所不同。

如在一个登录的action中验证成功后,重定向为显示用户信息的action: showInfo.do

一、在struts1 中实现


public class LoginAction extends Action {

public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) {
   
     //一些处理……

     //重定向
     ActionForward forward = new ActionForward("showInfo.do");
     forward.setRedirect(true);
     return forward ;
}
}


二、在struts2 中,因为执行函数返回结果不再是ActionForward ,而是一个字符串,所以不能再像struts1中那样跳转了。

在struts2中,重定向要在struts.xml中配置:

<action name="login" class="LoginAction">
   <result name="success" type="velocity">/pages/logok.vm</result>
   <result name="redirect_1" type="redirect">showInfo.do</result>
   <result name="redirect_2" type="redirect">showInfo.do?name=yangzi</result>
   <result name="redirect_3" type="redirect">showInfo.do?name=${name}</result>
   <result name="redirect_4" type= "red
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值