Struts forwards

A Struts forward is an object that is returned by an action and has two fields: a name and a path (typically the URL of a JSP file). The path indicates where a request is to be forwarded. A forward can be local (pertaining to a specific action) or global (available to any action).

A forward can be global or local. A global forward is defined in a Struts configuration file and invoked in a JSP page. A local forward is defined in a Struts configuration file in an action mapping and is invoked when the action is invoked.

 

Example of global forwards

Following is an example of global forwards in the struts-config.xml file of the struts-example sample application:

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

The logoff forward is invoked in mainMenu.jsp as follows:

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

 

Example of local forwards

Following is an example of local forwards in the struts-config.xml file of thestruts-example sample application:

<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>

 

Related concepts

Struts and model-view-controller design pattern
Struts actions
Web diagrams and the Web diagram editor
Struts configuration files

 

Related tasks

Creating a Web diagram
Editing a Web diagram
Loading a prebuilt Struts sample application

Related reference
Web diagram editor: pop-up menu

Feedback