Struts 2 Architecture
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.
Request Lifecycle in Struts 2 applications
- User Sends request: User sends a request to
the server for some resource.
- FilterDispatcher determines the appropriate
action: The FilterDispatcher looks at the request and then determines
the appropriate Action.
- Interceptors are applied: Interceptors
configured for applying the common functionalities such as workflow,
validation, file upload etc. are automatically applied to the request.
- Execution of Action: Then the action method
is executed to perform the database related operations like storing or
retrieving data from the database.
- Output rendering: Then the Result renders the
output.
- Return of Request: Then the request returns
through the interceptors in the reverse order. The returning request allows
us to perform the clean-up or additional processing.
- Display the result to user: Finally the
control is returned to the servlet container, which sends the output to the
user browser.
Image: Struts 2 high level overview of request
processing:

Struts 2 Architecture
Struts 2 is a very elegant and flexible front controller
framework based on many standard technologies like Java Filters, Java Beans,
ResourceBundles, XML etc.
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.
Exception Handling:
The Struts 2 Framework allows us to define exception
handlers and inceptors.
- Exception Handlers:
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.
- Interceptors:
The Interceptors are used to specify the "request-processing
lifecycle" for an action. Interceptors are configured to apply the
common functionalities like workflow, validation etc.. to the request.
Struts 2 Architecture
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.
Image: Struts 2 Architecture

The filter chain includes:
- Action ContextCleanUp filter:
The ActionContextCleanUp filter is optional and it is useful when
integration has to be done with other technologies like SiteMash Plugin.
- FilterDispatcher:
Next the FilterDispatch is called, which in turn uses the ActionMapper to
determine whether to invoke an Action or not. If the action is required to be
invoked, the FilterDispatcher delegates the control to the ActionProxy.
- ActionProxy:
The ActionProxy takes help from Configuration Files manager, which is
initialized from the struts.xml. Then the ActionProxy creates an ActionInvocation,
which implements the command pattern. The ActionInvocation process invokes
the Interceptors (if configured) and then invokes the action. The the
ActionInvocation looks for proper result. Then the result is executed, which
involves the rendering of JSP or templates.
Then the Interceptors are executed again in reverse order. Finally the
response returns through the filters configured in web.xml file. If the
ActionContextCleanUp filter is configured, the FilterDispatcher does not
clean the ThreadLocal ActionContext. If the ActionContextCleanUp filter is
not present then the FilterDispatcher will cleanup all the ThreadLocals
present.
In this section we have learnt about the Architecture
of Struts 2 Framework.
|
Current Comments
6 comments so far (post your own) View All Comments Latest 10 Comments:its so easy to learn struts2 framework and provided basic as easy
Posted by RuthraMoorthy on Friday, 02.29.08 @ 18:20pm | #50726
i want to learn struts2 frame work,how can i start the struts2 frame work(step by step process)
Posted by basavaraju on Friday, 07.20.07 @ 20:16pm | #21654
What are major differences between these two versions?? I know struts got compibned withwebworks . It will really help if major differences are posted . This site is really helpful for beginners .
Posted by jayashree on Tuesday, 05.29.07 @ 18:33pm | #17663
its really very useful application. I was totaly new to it n it helped me lot. Now please let me know that how to deploy my own struts 2.0 application?
Posted by priti on Monday, 04.16.07 @ 15:53pm | #14332
I need Struts 2.0 tutorial.If u have kindly send it me me.
Thanx
Posted by Aziz Abbas Khan on Thursday, 03.15.07 @ 00:54am | #11729
Good
Posted by Hatim on Thursday, 03.1.07 @ 21:45pm | #10076