轉發和重定向設置:
<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">index
Action.action</result>
</action>
上例中,如果deptAction中某個方法返回字符串為index,則將跳轉到indexAction去,執行indexAction的execute方法。
如果indexAction在其他包里面,則前面應加上包名,例:index/indexAction