Struts 转发

Struts 转发是一个由操作返回的对象并且该对象具有两个字段:名称和路径(通常为 JSP 文件的 URL)。路径指示要向何处转发请求。转发可以是局部的(与特定操作有关)或全局的(对于任何操作都可用)。

转发可以是全局的,也可是局部的。全局转发是在 Struts 配置文件中定义的,且是在 JSP 页中调用的。局部转发是在 Struts 配置文件中的操作映射中定义的,且在调用操作时被调用。

全局转发示例

以下是 struts-example 样本应用程序struts-config.xml 文件中全局转发的示例:

<global-forwards>
  <forward   name="logoff"               path="/logoff.do"/>
  <forward   name="logon"                path="/logon.jsp"/>
  <forward   name="success"              path="/mainMenu.jsp"/>
</global-forwards>

logoff 转发是按如下所示在 mainMenu.jsp 中调用的:

<html:link forward="logoff"><bean:message key="mainMenu.logoff"/></html:link>

局部转发示例

以下是 struts-example 样本应用程序的 struts-config.xml 文件中局部转发的示例:

<action    path="/editSubscription"
           type="org.apache.struts.webapp.example.EditSubscriptionAction"
      attribute="subscriptionForm"
          scope="request"
       validate="false">
  <forward name="failure"              path="/mainMenu.jsp"/>
  <forward name="success"              path="/subscription.jsp"/>
</action>
相关概念
Struts 和模型-视图-控制器设计模式
Struts 操作
Web 图和 Web 图编辑器
Struts 配置文件
相关任务
创建 Web 图
编辑 Web 图
装入预先构建的 Struts 样本应用程序
相关参考
Web 图编辑器:弹出菜单
反馈
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.