IncludeAction in Struts

By: Fazal Emailed: 1646 times Printed: 2123 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

IncludeAction is much like ForwardAction except that the resulting resource is included in the HTTP response instead of being forwarded to. It is rarely used. Its only significant use is to integrate legacy applications with Struts transparently. Consider a web site that aggregates information from disparate sources - some of which are non-Struts. The JSP for such a web site consists of <jsp:include>s to include different resources. One of such <jsp:include> that might be as follows: <jsp:include page="/xoom/LegacyServletA" />

It is very clear from the value of the page attribute that it is a non-Struts resource. Wouldn't it be better to have a <jsp:include> that pretends as if the resource exists in the current Struts application? It would be ideal if the page include looked as follows:

<jsp:include page="/App1/legacyA.do" />

The /legacyA.do cannot be a ForwardAction because it would perform a HTTP Forward to the above resource instead of including the resource in the HTTP response. Since the HTTP Response OutputStream closes (The J2EE jargon for this is the response has been committed) after HTTP Forward, the servlet container cannot process the rest of the JSP and include its response in the OutputStream. Consequently it throws a IllegalStateException with a message that “Response is already committed". IncludeAction addresses this problem. Instead of forwarding to the specified resource, it includes the resource in the current response. Consequently the output of the LegacyServletA is displayed in the same HTML as that of the Struts application. You have to add the following ActionMapping in the Struts Config file:

<action path="/legacyA"
parameter="/xoom/LegacyServletA"
type="org.apache.struts.actions.IncludeAction" />

The parameter attribute indicates the actual resource that has to be included in the response. As mentioned earlier, the use of IncludeAction is limited to including responses from existing Servlet in the current page. This requires the use of <jsp:include> in the page. If you web application is aggregating response from legacy servlet applications, portlets seems to be the way to go. Portlet API - JSR 168 has been finalized and it is matter of time before you can develop standardized portals aggregating contents from disparate web applications. Tiles framework is the way to go if you are on a short-term project that wants to aggregate information now (From different applications or may be from various Actions in the same Struts application). Tiles provides a robust alternative to the primitive <jsp:include>.

This is an excerpt from the book "Struts Survival Guide". You can get more details from that book.


Struts Home | All Struts Tutorials | Latest Struts Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(1)


1. View Comment

very good explanation for Include Action in struts.

View Tutorial          By: VIshwanath at 2011-03-21 06:00:22

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Fazal
The Tag Life Cycle with Attributes in JSP
Using Shift Operators in C
IncludeAction in Struts
typedef example program in C
Arithmetic Evaluation Using the Expression Language in JSP
Tutorial on Complicated Declarations in C
Static Variables in C
getPosition() the right strategy in getting GPS
Precedence and Order of Evaluation in C
File Copying in C
JSF Life Cycle
Getting User Input Using cin in C++
UDP Datagram sample in J2ME
GUI components and menu based J2ME Applications.
A Serialization Example in Java

More Tutorials in Struts
Configuring JDBC DataSources in Struts
Struts Classes
FAQ: Why was reload removed from Struts (since 1.1)?
FAQ: Why are my checkboxes not being set from ON to OFF?
Using JavaScript to submit a form in Struts
How to prepopulate a form in Struts
Simple example of using the requiredif Validator rule in Struts
Chaining actions in Struts
When is the best time to validate input in Struts
What is a Plug-in and how to use Java plug-ins with Struts?
7 Best Practices of Struts
Origin and Architecture of Struts
ActionErrors and ActionError in Struts
Tutorial on Struts Configuration File - struts-config.xml in Struts - from the book: Struts Survival Guide. Basics to Best Practices
Handling multiple buttons in HTML Form in Struts

More Latest News
Most Viewed Articles (in Struts )
Tutorial on Struts Configuration File - struts-config.xml in Struts - from the book: Struts Survival Guide. Basics to Best Practices
Simple example of using the requiredif Validator rule in Struts
Creating Struts Modules
ActionErrors and ActionError in Struts
Struts 1 vs Struts 2
MVC Architecture (Model 2 Architecture)
ForwardAction in Struts
What is Struts? Which Version of Struts to use?
What is a Model View Controller (MVC) Model?
History of Struts
Editing web.xml in a Struts Application
Struts and Tiles - Steps to use Struts and Tiles
Using Checkbox & Radio Tags, html:select, html:options in Struts Forms
Configuring JDBC DataSources in Struts
Downloading and installing Struts
Most Emailed Articles (in Struts)
History of Struts
ActionErrors and ActionError in Struts
The directories and files of a Struts application
Using Checkbox & Radio Tags, html:select, html:options in Struts Forms
What is a Model View Controller (MVC) Model?
Creating the first application using Struts 2
Model 1 Architecture
Installing and configuring Tomcat and Struts
Creating Struts Modules
Struts 1 vs Struts 2
Using Multibox in Struts
Guidelines for Struts Application Development
7 Best Practices of Struts
FAQ: Why was reload removed from Struts (since 1.1)?
Using JavaScript to submit a form in Struts