How to use IncludeAction in Struts

In this tutorial you will learn about use of another struts built-in Action class, which in IncludeAction.

The IncludeAction class provides a mechanism for including the contents of a specified URL. This action behaves similarly to ForwardAction, but instead of forwarding to the specified URL, the specified URL is included. This action is useful when you want to include the contents of one page in another.

Using IncludeAction is quite easy. Just create action mapping entries in the Struts configuration file as shown below:

<action path="/includeSome" type="org.apache.struts.actions.IncludeAction"
            parameter="/includeSome.jsp" />

For each page you want to include, you must create an action mapping. Each action mapping uses IncludeAction, but specifies a different path for the action. The parameter attribute specifies the URL that will be included when the specified path is accessed.

There is also one alternative solution to using IncludeAction is to use the include attribute of the action tag in the Struts configuration file, as shown here:

<action path="/includeSome" include="/includeSome.jsp" />

These two approaches effectively give the same results.