Skip to Main Content
Jakarta Struts Cookbook
book

Jakarta Struts Cookbook

by Bill Siggelkow
February 2005
Intermediate to advanced content levelIntermediate to advanced
528 pages
12h 53m
English
O'Reilly Media, Inc.
Content preview from Jakarta Struts Cookbook

6.5. Forwarding Requests

Problem

You want to provide an action that forwards a request to any action, JSP page, servlet, or other resource of your web application.

Solution

Use a forwarding action. Specifying the module-relative path to the resource as the value of the forward attribute is the most convenient way:

<action  path="/ForwardTest"
    forward="/forward_test.jsp"/>

Alternatively, if you use a custom RequestProcessor, which overrides the processForwardConfig( ) method, you must use the Struts built-in ForwardAction, specifying the context-relative path for the value of the parameter attribute.

<action  path="/ForwardActionTest"
         type="org.apache.struts.actions.ForwardAction"
    parameter="/forward_test.jsp"/>

Discussion

Struts provides two mechanisms for creating an action that forwards directly to a specified resource. You can use the forward attribute or the ForwardAction. In most situations, the forward attribute will work just fine. The value of the attribute is treated as a module-relative path. At request time, the RequestProcessor checks the action mapping specifies a forward attribute. If so, it converts the forward attribute value to a context-relative path by adding the module prefix to the front of the path. The request processor then hands the request and response to the RequestDispatcher.forward( ) method and immediately returns.

The ForwardAction is a Struts prebuilt action class included with the Struts distribution. This Action forwards the request to the path specified as ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming Jakarta Struts

Programming Jakarta Struts

Chuck Cavaness
Beginning Spring Framework 2

Beginning Spring Framework 2

Bruce Snyder, Sing Li, Anne Horton, Thomas Van de Velde, Naveen Balani, Christian Dupuis
Java Cookbook

Java Cookbook

Ian F. Darwin
Struts 2 in Action

Struts 2 in Action

J. Scott Stanlick, Chad Michael Davis, Donald J. Brown

Publisher Resources

ISBN: 059600771XSupplemental ContentErrata Page