IncludeAction


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 >. Chapter 7 provides an in-depth coverage of Tiles in conjunction with Struts.




Struts Survival Guide. Basics to Best Practices
Struts Survival Guide: Basics to Best Practices (J2ee Survival Series)
ISBN: 0974848808
EAN: 2147483647
Year: 2004
Pages: 96

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net