<div dir="ltr" style="text-align: justify;">
<p>Struts and webwork has joined together to develop the Struts 2 Framework. Struts 2 Framework is very extensible and elegant for the development of enterprise web application of any size. In this section we are going to explain you the architecture of Struts 2 Framework.</p>
<p><i><b>Struts 2 Framework = Struts 1 + webwork</b></i></p>
<h2><b>Request Lifecycle in Struts 2 applications</b></h2>
<p><b>User Sends request:</b> User sends a request to the server for some resource.</p>
<p><b>FilterDispatcher determines the appropriate action:</b> The <i><b>FilterDispatcher </b></i>looks at the request and then determines the appropriate Action.</p>
<p><b>Interceptors are applied:</b> <i><b>Interceptors </b></i>configured for applying the common functionality such as workflow, validation, file upload etc. are automatically applied to the request.</p>
<div id="ads-id" align="center"></div>
<p><b>Execution of Action:</b> Then the action method is executed to perform the database related operations like storing or retrieving data from the database.</p>
<p><b>Output rendering:</b> Then the Result renders the output.</p>
<p><b>Return of Request: </b>Then the request returns through the interceptors in the reverse order. The returning request allows us to perform the clean-up or additional processing.</p>
<p><b>Display the result to user:</b> Finally the control is returned to the servlet container, which sends the output to the user browser.</p>
<div class="separator" style="clear: both; text-align: center;"><img src="https://dineshonjava.com/wp-content/uploads/2013/07/struts-2-request-cycle.png" border="0" /></div>
<p><b>Exception Handling:</b></p>
<p>The Struts 2 Framework allows us to define exception handlers and interceptors.</p>
<p><b>Exception Handlers:</b><br />
Exception handlers allows us to define the exception handling procedure on global and local basis. Framework catches the exception and then displays the page of our choice with appropriate message and exception details.</p>
<p><b>Interceptors:</b><br />
The Interceptors are used to specify the <i><b>&#8220;request-processing lifecycle&#8221;</b></i> for an action. Interceptors are configured to apply the common functionality like workflow, validation etc.. to the request.</p>
<h2><b>Struts 2 Architecture</b></h2>
<p>Struts 2 is a very elegant and flexible front controller framework based on many standard technologies like <i><b>Java Filters, Java Beans, ResourceBundles, XML</b></i> etc.</p>
<p>For the Model, the framework can use any data access technologies like JDBC, EJB, Hibernate etc and for the View, the framework can be integrated with JSP, JTL, JSF, Jakarta Velocity Engine, Templates, PDF, XSLT etc.</p>
<p>The following diagram depicts the architecture of Struts 2 Framework and also shows the the initial request goes to the servlet container such as tomcat, which is then passed through standard filer chain.</p>
<div class="separator" style="clear: both; text-align: center;"><img src="https://dineshonjava.com/wp-content/uploads/2013/07/Struts2-Architecture.png" border="0" /></div>
<h2><b>The filter chain includes:</b></h2>
<p><b><i>ActionContextCleanUp </i>filter:</b><br />
The <i><b>ActionContextCleanUp </b></i>filter is optional and it is useful when integration has to be done with other technologies like <i><b>SiteMash </b></i>Plugin.</p>
<p><i><b>FilterDispatcher:</b></i><br />
Next the <i><b>FilterDispatch </b></i>is called, which in turn uses the <i><b>ActionMapper </b></i>to determine whether to invoke an Action or not. If the action is required to be invoked, the <i><b>FilterDispatcher </b></i>delegates the control to the <i><b>ActionProxy</b></i>.</p>
<p><i><b>ActionProxy:</b></i><br />
The <i><b>ActionProxy </b></i>takes help from <i><b>Configuration Files manager,</b></i> which is initialized from the <i><b>struts.xml.</b></i></p>
<p>Then the <i><b>ActionProxy </b></i>creates an <i><b>ActionInvocation</b></i>, which implements the command pattern. The <i><b> </b></i><br />
<i><b>ActionInvocation </b></i>process invokes the <i><b>Interceptors </b></i>(if configured) and then invokes the action. The the <i><b>ActionInvocation </b></i>looks for proper result. Then the result is executed, which involves the rendering of JSP or templates.</p>
<p>Then the <i><b>Interceptors </b></i>are executed again in reverse order. Finally the response returns through the filters configured in <i><b>web.xml</b></i> file. If the <i><b>ActionContextCleanUp </b></i>filter is configured, the <i><b>FilterDispatcher </b></i>does not clean the <i><b>ThreadLocal </b><b>ActionContext</b></i>. If the <i><b>ActionContextCleanUp </b></i>filter is not present then the <i><b>FilterDispatcher </b></i>will cleanup all the <i><b>ThreadLocals </b></i>present.</p>
<div style="background-color: pink; border-width: thin; text-align: center;"><b><;<;<a href="https://dineshonjava.com/2013/07/introduction-to-struts-2-framework.html">Previous</a> <;<; || <a href="https://dineshonjava.com/2013/07/struts-2-baby-step-to-learn.html">Index </a>|| >;>;<a href="https://dineshonjava.com/2013/07/setting-up-struts-2-in-eclipse.html">Next</a> >;>;</b></div>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/model-1-and-model-2-mvc-architecture/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/setting-up-struts-2-in-eclipse/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '401'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…