Struts is a flexible control layer based on standard technologies like Java Filters, JavaBeans, ResourceBundles, Locales, and XML, as wellas various OpenSymphony
packages, like OGNL and XWork.
For the Model, the framework can interact with standard data access technologies, like JDBCand EJB,as well as most any third-party packages, like Cayenne,Hibernate,or iBATIS.
For the View, the framework works well with JavaServer Pages,including JSTL and JSF, as well as FreeMarkeror VelocityTemplates, PDF, XSLT, and other presentation systems.
Aside from actions and results, we can specify exception handlersand interceptors.
Exception handlersdeclare how to handle an exception on aglobal or local basis. Instead of sprinking source code with try .. catch blocks, we can let the framework catch the exception and display the page of our choice. The page can display an appropriate message and details from the exception.
Interceptorsspecify the "request-processing lifecycle" for an action. (What happens to the request before and after the Action class fires.) We can specify both global and local lifecycles. If some actions respond to AJAX, SOAP, or JSF requests, we can simplify the lifecycle, and even just "pass through" the request, if needed. However,these are special cases, and most applications can use the default interceptor stack, "out of the box".
The diagram describes the framework's architecture.
In the diagram, an initial request goes to the Servlet container (such as Jetty or Resin) which is passed through a standard filter chain. The chain includes the (optional) ActionContextCleanUpfilter, which is useful when integrating technologies such as SiteMesh Plugin. Next, the required FilterDispatcheris called, which in turn consults the ActionMapperto determine if the request shouldinvoke an action.
If the ActionMapper determines that an Action should be invoked, the FilterDispatcher delegates control to the ActionProxy. The ActionProxy consults the framework Configuration Filesmanager (initializedfrom the struts.xmlfile). Next, the ActionProxy creates an ActionInvocation, which is responsible for the command patternimplementation. This includes invoking any Interceptors(the beforeclause) in advance of invoking the Actionitself.
Once the Action returns, the ActionInvocation is responsible for looking up the proper resultassociated with the Action resultcodemapped in struts.xml. The result is then executed, which often (but not always, as is the case for Action Chaining) involves a template writtenin JSPor FreeMarkerto be rendered. While rendering, the templates can use the Struts Tagsprovided by the framework. Some of those components will work with the ActionMapper to render proper URLs for additional requests.
Allobjects in this architecture (Actions, Results, Interceptors, and so forth) are created by an ObjectFactory. This ObjectFactory is pluggable. We can provide our own ObjectFactory for any reason that requires knowing when objects in the framework are created. A popular ObjectFactory implementation uses Spring as provided by the Spring Plugin.
Interceptors are executed again (in reverse order, calling the afterclause). Finally, the response returns through the filters configured in the web.xml. If the ActionContextCleanUp filter is present, the FilterDispatcher will notclean up the ThreadLocal ActionContext.If the ActionContextCleanUp filter is not present, the FilterDispatcherwill cleanup all ThreadLocals.