struts2 重定向
如在一个登录的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