[整理]在struts2.0中 action跳转

在struts2.0中 action跳转有两种方式,特别要指出的是仅在同一package范围内生效。不同Package的Action跳转使用param参数即可。

第一种通过action 转接
第二种为action链方式。

方法一:
1. 设置type="redirect"
<package   name="struts" extends="struts-default">
 <action name="login" class="com.aihua.example.LoginAction">
  <result name="success" type="redirect">action name </result>
  <result name="error">/index.jsp </result>
 </action>     
</package>

方法二 action链2.设置 type="chain"
<package   name="struts" extends="struts-default">
 <action name="login" class="com.aihua.example.LoginAction">
  <result name="success" type="chain" >action name</result>
  <result name="error">/index.jsp </result>
 </action>  
</package>
当 type为chain 时,说明是action链,运行完第一个action java文件接着会运行第二个action JAVA 文件,相当于forward(客户端的url不会改变).当type为redirect时,说明会跳转到第二

个action的url (客户端的url会改变)


<package name="admin" extends="struts-default" namespace="/admin">
<!-- 结算单导入查询 -->
        <action name="settlementSearchAction" class="settlementSearchAction">
            <result name="settlement_list" type="velocity" >/web/channel/settlement/settlement_list.html</result>
            <result name="settlementDetail_list" type="velocity" >/web/channel/settlement/settlementDetail_list.html</result>
            <result name="gotoTest" type="chain">
             <param name="actionName">settlementTestAction</param>
      <!-- 如果指定方法,那么就跳转到指定的方法,不指定或者指定的方法不存在则跳转到默认方法execute()-->
             <param name="method">myTest</param>
      <!---如果是别的包的还需要<param name="namespace">/mygod</param> ,如果不声明,默认全部Package中查找Action-->
            </result>
        </action>
<action name="settlementTestAction" class="com.aspire.mm.channel.admin.module.settlement.action.SettlementTestAction">
           
        </action>
</package>

<package name="struts2_Stipend" extends="struts-default">
    <action name="StipendManage_*" class="com.dhcc.demo.eform.stipend.action.StipendAction" method="{1}">
      <result name="toList" type="redirect">demo/eform/stipend/list.jsp</result>
      <result name="add" type="redirect">demo/eform/stipend/list.jsp</result>
      <result name="toUpdate" type="dispatcher">demo/eform/stipend/update.jsp</result>
      <result name="toDetail" type="dispatcher">demo/eform/stipend/detail.jsp</result>
      <!-- <result name="toProcessStartAction" type="dispatcher">common/request/dispatcher.jsp</result> -->
      <result name="toProcessStartAction" type="chain">
        <param name="actionName">ProcessStartManage</param>
  <!-- 如果指定方法,那么就跳转到指定的方法,不指定或者指定的方法不存在则跳转到默认方法execute()-->
         <param name="method">StartFormSubmit</param>
      </result>
     
    </action>
</package>
<package name="struts2_ProcessStart" extends="struts-default">
    <action name="ProcessStartManage_*" class="com.dhcc.bpm.worklist.start.action.ProcessStartAction" method="{1}">
      <result name="toStart" type="dispatcher">bpm/worklist/start/start.jsp</result>
      <result name="startSuccess" type="dispatcher">bpm/worklist/start/success.jsp</result>
      <result name="toList" type="redirect">bpm/worklist/running/index.jsp</result>
      <result name="add" type="redirect">bpm/processdef/activityrule/list.jsp</result>
      <result name="toUpdate" type="dispatcher">bpm/processdef/activityrule/update.jsp</result>
      <result name="toDetail" type="dispatcher">bpm/processdef/activityrule/detail.jsp</result>
      <result name="toActivityRuleIndex" type="dispatcher">bpm/processdef/activityrule/index.jsp</result>
    </action>
</package>

posted on 2013-10-28 11:44  unimme  阅读(419)  评论(0编辑  收藏  举报

导航