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

First create a new Dynamic Web Project and configure it as Maven Project. For Reference, Click Here

Add the following dependencies in pom.xml


1. Create IncludeAction

Create the Action Mapping in struts-config.xml

    <action path="/helloWorld" type="org.apache.struts.actions.IncludeAction" parameter="/helloWorld.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.

2. Create JSP Page

You use the action as you would original resource. In other words, you would change JSP tags that look like this:

<jsp include page="helloWorld"/>

to this:

<jsp include page=""/>

Now create helloWorld.jsp file that display Hello World!!! message.


<%@taglib uri="" prefix="bean"%>
<h1>Hello World!!!

The folder structure of the example is shown below in Figure 7.1

Figure 7.1 Figure 7.1

You can download the source code of this example here.

No comments yet.

Leave a Reply