zoukankan      html  css  js  c++  java
  • Struts2理解——转发和重定向

        转发和重定向设置:        
    <action name="deptAction" class="com.syaccp.erp.action.DeptAction">
                <result name="success">/WEB-INF/jsp/basic/dept_list.jsp</result>
                <result name="editView">/WEB-INF/jsp/basic/dept_edit.jsp</result>
    </action> 
        上例action中,success对应的视图是通过默认的转发(dispatch)跳转的。editView作为增删改的一部分,应该通过重定向来跳转页面,这样必须显式声明type=redirect,来达到重定向的效果。这时editView的内容改为action中一个方法更合适。如:
    <action name="deptAction" class="com.syaccp.erp.action.DeptAction">
                <result name="success">/WEB-INF/jsp/basic/dept_list.jsp</result>
                <result name="editView" type="redirect">deptAction!select.action</result>
    </action>
      这里在执行edit方法后返回editView字符串,将会再执行select方法,跟DeptEditServlet里response.sendRedirect("DeptListServlet")类似
    上例只是重定向同一个Action类中的其他方法,开发中可能还需要重定向到其他Action类中,这时就需要用到type属性的另一个值:redirectAction:
     <action name="deptAction" class="com.syaccp.erp.action.DeptAction">
                <result name="success">/WEB-INF/jsp/basic/dept_list.jsp</result>
                <result name="editView" type="redirect">deptAction!select.action</result>
                <result name="index" type="redirectAction">indexAction.action</result>
    </action>
     上例中,如果deptAction中某个方法返回字符串为index,则将跳转到indexAction去,执行indexAction的execute方法。
    如果indexAction在其他包里面,则前面应加上包名,例:index/indexAction




  • 相关阅读:
    “键鼠耕耘,IT家园”,博客园2010T恤正式发布
    解决jQuery冲突问题
    上周热点回顾(5.316.6)
    博客园电子期刊2010年5月刊发布啦
    上周热点回顾(6.76.13)
    Chrome/5.0.375.70 处理 <pre></pre> 的 Bug
    [转]C# MemoryStream和BinaryFormatter
    [转]Android adb不是内部或外部命令 问题解决
    [转]HttpWebRequest解析 作用 介绍
    财富中文网 2010年世界500强排行榜(企业名单)
  • 原文地址:https://www.cnblogs.com/xiaona/p/f8788f093e19e360d545bd3d5810aab3.html
Copyright © 2011-2022 走看看