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.
Read now
Unlock full access